Use file scope namespaces
This commit is contained in:
@@ -1,30 +1,24 @@
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
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)
|
||||
{
|
||||
//Log.Debug("Worker läuft...");
|
||||
await Task.Delay(1000, stoppingToken);
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task StopAsync(CancellationToken cancellationToken)
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
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 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()
|
||||
.MinimumLevel.Debug()
|
||||
.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)
|
||||
.CreateLogger();
|
||||
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.UseWindowsService()
|
||||
.ConfigureAppConfiguration((context, config) =>
|
||||
{
|
||||
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
|
||||
})
|
||||
.UseSerilog()
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
var config = new ConfigurationBuilder()
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.Build();
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.UseWindowsService()
|
||||
.ConfigureAppConfiguration((context, config) =>
|
||||
{
|
||||
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
|
||||
})
|
||||
.UseSerilog()
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
var config = new ConfigurationBuilder()
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.Build();
|
||||
|
||||
Config.general = config.GetSection("General").Get<General>();
|
||||
Config.general = config.GetSection("General").Get<General>();
|
||||
|
||||
webBuilder.UseStartup<Startup>();
|
||||
webBuilder.UseKestrel(options =>
|
||||
webBuilder.UseStartup<Startup>();
|
||||
webBuilder.UseKestrel(options =>
|
||||
{
|
||||
options.ListenAnyIP(Config.general.ThisPort);
|
||||
})
|
||||
@@ -50,6 +50,5 @@ namespace TemplateNETService.Business
|
||||
{
|
||||
services.AddHostedService<BaseWorker>();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -3,26 +3,25 @@ using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
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();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
app.UseDeveloperExceptionPage();
|
||||
|
||||
app.UseRouting();
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
}
|
||||
|
||||
services.AddControllers();
|
||||
}
|
||||
}
|
||||
|
||||
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