Use file scope namespaces
This commit is contained in:
@@ -1,30 +1,24 @@
|
|||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TemplateNETService.Business;
|
using TemplateNETService.Business;
|
||||||
|
|
||||||
namespace TemplateNETService
|
namespace TemplateNETService;
|
||||||
|
|
||||||
|
internal class BaseWorker : BackgroundService
|
||||||
{
|
{
|
||||||
internal class BaseWorker : BackgroundService
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
{
|
{
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
Log.Debug($"Service is started on port {Config.general.ThisPort}...");
|
||||||
{
|
|
||||||
Log.Debug($"Service is started on port {Config.general.ThisPort}...");
|
|
||||||
|
|
||||||
while (!stoppingToken.IsCancellationRequested)
|
while (!stoppingToken.IsCancellationRequested)
|
||||||
{
|
|
||||||
//Log.Debug("Worker läuft...");
|
|
||||||
await Task.Delay(1000, stoppingToken);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task StopAsync(CancellationToken cancellationToken)
|
|
||||||
{
|
{
|
||||||
Log.Debug("Service stopped...");
|
//Log.Debug("Worker läuft...");
|
||||||
|
await Task.Delay(1000, stoppingToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public override async Task StopAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
Log.Debug("Service stopped...");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,14 +7,14 @@ using Serilog.Events;
|
|||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using TemplateNETService.Models;
|
using TemplateNETService.Models;
|
||||||
|
|
||||||
namespace TemplateNETService.Business
|
namespace TemplateNETService.Business;
|
||||||
|
|
||||||
|
public class Program
|
||||||
{
|
{
|
||||||
public class Program
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
Directory.CreateDirectory("_LOG");
|
||||||
{
|
Log.Logger = new LoggerConfiguration()
|
||||||
Directory.CreateDirectory("_LOG");
|
|
||||||
Log.Logger = new LoggerConfiguration()
|
|
||||||
.WriteTo.Console()
|
.WriteTo.Console()
|
||||||
.MinimumLevel.Debug()
|
.MinimumLevel.Debug()
|
||||||
.MinimumLevel.Override("Microsoft", LogEventLevel.Error) // Für Microsoft-Komponenten nur Warning+
|
.MinimumLevel.Override("Microsoft", LogEventLevel.Error) // Für Microsoft-Komponenten nur Warning+
|
||||||
@@ -22,27 +22,27 @@ namespace TemplateNETService.Business
|
|||||||
.Filter.ByExcluding(logEvent => logEvent.Level == LogEventLevel.Information)
|
.Filter.ByExcluding(logEvent => logEvent.Level == LogEventLevel.Information)
|
||||||
.CreateLogger();
|
.CreateLogger();
|
||||||
|
|
||||||
CreateHostBuilder(args).Build().Run();
|
CreateHostBuilder(args).Build().Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||||
Host.CreateDefaultBuilder(args)
|
Host.CreateDefaultBuilder(args)
|
||||||
.UseWindowsService()
|
.UseWindowsService()
|
||||||
.ConfigureAppConfiguration((context, config) =>
|
.ConfigureAppConfiguration((context, config) =>
|
||||||
{
|
{
|
||||||
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
|
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
|
||||||
})
|
})
|
||||||
.UseSerilog()
|
.UseSerilog()
|
||||||
.ConfigureWebHostDefaults(webBuilder =>
|
.ConfigureWebHostDefaults(webBuilder =>
|
||||||
{
|
{
|
||||||
var config = new ConfigurationBuilder()
|
var config = new ConfigurationBuilder()
|
||||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
Config.general = config.GetSection("General").Get<General>();
|
Config.general = config.GetSection("General").Get<General>();
|
||||||
|
|
||||||
webBuilder.UseStartup<Startup>();
|
webBuilder.UseStartup<Startup>();
|
||||||
webBuilder.UseKestrel(options =>
|
webBuilder.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
options.ListenAnyIP(Config.general.ThisPort);
|
options.ListenAnyIP(Config.general.ThisPort);
|
||||||
})
|
})
|
||||||
@@ -50,6 +50,5 @@ namespace TemplateNETService.Business
|
|||||||
{
|
{
|
||||||
services.AddHostedService<BaseWorker>();
|
services.AddHostedService<BaseWorker>();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -3,26 +3,25 @@ using Microsoft.AspNetCore.Hosting;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
namespace TemplateNETService
|
namespace TemplateNETService;
|
||||||
|
|
||||||
|
public class Startup
|
||||||
{
|
{
|
||||||
public class Startup
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
public void ConfigureServices(IServiceCollection services)
|
services.AddControllers();
|
||||||
{
|
|
||||||
services.AddControllers();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
||||||
{
|
|
||||||
if (env.IsDevelopment())
|
|
||||||
app.UseDeveloperExceptionPage();
|
|
||||||
|
|
||||||
app.UseRouting();
|
|
||||||
app.UseEndpoints(endpoints =>
|
|
||||||
{
|
|
||||||
endpoints.MapControllers();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
|
{
|
||||||
|
if (env.IsDevelopment())
|
||||||
|
app.UseDeveloperExceptionPage();
|
||||||
|
|
||||||
|
app.UseRouting();
|
||||||
|
app.UseEndpoints(endpoints =>
|
||||||
|
{
|
||||||
|
endpoints.MapControllers();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user