Добавлена логгирование всех непредвиденных ошибок
This commit is contained in:
parent
25e6f2df67
commit
b570c25680
@ -22,23 +22,39 @@ namespace AirBomber
|
||||
ConfigureServices(services);
|
||||
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
||||
{
|
||||
Application.Run(serviceProvider.GetRequiredService<FormMapWithSetAirplanes>());
|
||||
try
|
||||
{
|
||||
Application.Run(serviceProvider.GetRequiredService<FormMapWithSetAirplanes>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
GetLogger().Fatal(ex, "Íåïðåäâèäåííàÿ îøèáêà.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Serilog.ILogger GetLogger()
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
|
||||
.Build();
|
||||
|
||||
var logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(configuration)
|
||||
.WriteTo.Logger(lc => lc
|
||||
.Filter.ByIncludingOnly(f =>
|
||||
f.Level == Serilog.Events.LogEventLevel.Information)
|
||||
.WriteTo.File("action_user.txt"))
|
||||
.CreateLogger();
|
||||
return logger;
|
||||
}
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<FormMapWithSetAirplanes>()
|
||||
.AddLogging(option =>
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
|
||||
.Build();
|
||||
|
||||
var logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(configuration)
|
||||
.CreateLogger();
|
||||
|
||||
var logger = GetLogger();
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddSerilog(logger);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user