diff --git a/ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.cs b/ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.cs index 5c76ab5..af3463c 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.cs @@ -164,9 +164,9 @@ namespace ProjectStormtrooper _logger.LogWarning("Отмена удаления объекта"); return; } - int pos = Convert.ToInt32(maskedTextBoxNumber.Text); try { + int pos = Convert.ToInt32(maskedTextBoxNumber.Text); var removedObj = obj - pos; if (removedObj != null) { diff --git a/ProjectStormtrooper/ProjectStormtrooper/Program.cs b/ProjectStormtrooper/ProjectStormtrooper/Program.cs index b4e005c..7e557e4 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/Program.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/Program.cs @@ -1,6 +1,7 @@ +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using NLog.Extensions.Logging; +using Serilog; namespace ProjectStormtrooper { @@ -27,8 +28,17 @@ namespace ProjectStormtrooper services.AddSingleton() .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(); + option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); + option.AddSerilog(logger); }); } } diff --git a/ProjectStormtrooper/ProjectStormtrooper/ProjectStormtrooper.csproj b/ProjectStormtrooper/ProjectStormtrooper/ProjectStormtrooper.csproj index c73213b..98b6f27 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/ProjectStormtrooper.csproj +++ b/ProjectStormtrooper/ProjectStormtrooper/ProjectStormtrooper.csproj @@ -9,18 +9,27 @@ + + + Always + Always + + + + + diff --git a/ProjectStormtrooper/ProjectStormtrooper/appSettings.json b/ProjectStormtrooper/ProjectStormtrooper/appSettings.json new file mode 100644 index 0000000..dde3405 --- /dev/null +++ b/ProjectStormtrooper/ProjectStormtrooper/appSettings.json @@ -0,0 +1,20 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "log_.log", + "rollingInterval": "Day", + "outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}" + } + } + ], + "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], + "Properties": { + "Application": "Planes" + } + } +} \ No newline at end of file diff --git a/ProjectStormtrooper/ProjectStormtrooper/nlog.config b/ProjectStormtrooper/ProjectStormtrooper/nlog.config deleted file mode 100644 index 23748aa..0000000 --- a/ProjectStormtrooper/ProjectStormtrooper/nlog.config +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - \ No newline at end of file