From cf5bb6bee12a337446aedeb69cfd25e233dca158 Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Mon, 21 Nov 2022 09:27:37 +0400 Subject: [PATCH] Serilog --- .../AntiAircraftGun/AntiAircraftGun.csproj | 14 ++++---------- AntiAircraftGun/AntiAircraftGun/Program.cs | 11 ++++++++++- .../AntiAircraftGun/SetAntiAircraftGunsGeneric.cs | 2 +- AntiAircraftGun/AntiAircraftGun/nlog.config | 13 ------------- AntiAircraftGun/AntiAircraftGun/seriLog.json | 12 ++++++++++++ 5 files changed, 27 insertions(+), 25 deletions(-) delete mode 100644 AntiAircraftGun/AntiAircraftGun/nlog.config create mode 100644 AntiAircraftGun/AntiAircraftGun/seriLog.json diff --git a/AntiAircraftGun/AntiAircraftGun/AntiAircraftGun.csproj b/AntiAircraftGun/AntiAircraftGun/AntiAircraftGun.csproj index 3eb1f1d..3483561 100644 --- a/AntiAircraftGun/AntiAircraftGun/AntiAircraftGun.csproj +++ b/AntiAircraftGun/AntiAircraftGun/AntiAircraftGun.csproj @@ -8,22 +8,16 @@ enable - - - - - - - Always - - - + + + + diff --git a/AntiAircraftGun/AntiAircraftGun/Program.cs b/AntiAircraftGun/AntiAircraftGun/Program.cs index f03c116..7b43459 100644 --- a/AntiAircraftGun/AntiAircraftGun/Program.cs +++ b/AntiAircraftGun/AntiAircraftGun/Program.cs @@ -1,6 +1,8 @@ +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; +using Serilog; namespace AntiAircraftGun { @@ -27,8 +29,15 @@ namespace AntiAircraftGun services.AddSingleton() .AddLogging(option => { + var configuration = new ConfigurationBuilder() + .AddJsonFile("C:\\Σνθβεπρθςες\\2 κσπρ\\ΠΟΟ\\AntiAircraftGun\\AntiAircraftGun\\AntiAircraftGun\\seriLog.json") + .Build(); + + var Logger = new LoggerConfiguration() + .ReadFrom.Configuration(configuration) + .CreateLogger(); option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); + option.AddSerilog(Logger); }); } } diff --git a/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs b/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs index 29b3012..b5b0f68 100644 --- a/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs +++ b/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs @@ -62,7 +62,7 @@ namespace AntiAircraftGun /// public T Remove(int position) { - if (position < 0 || position >= _places.Count) throw new AntiAircraftGunNotFoundException(position); ; + if (position >= _places.Count) throw new AntiAircraftGunNotFoundException(position); if (_places[position] == null) throw new AntiAircraftGunNotFoundException(position); T removed = _places[position]; _places.RemoveAt(position); diff --git a/AntiAircraftGun/AntiAircraftGun/nlog.config b/AntiAircraftGun/AntiAircraftGun/nlog.config deleted file mode 100644 index 6d5e25e..0000000 --- a/AntiAircraftGun/AntiAircraftGun/nlog.config +++ /dev/null @@ -1,13 +0,0 @@ -ο»Ώ - - - - - - - - - - \ No newline at end of file diff --git a/AntiAircraftGun/AntiAircraftGun/seriLog.json b/AntiAircraftGun/AntiAircraftGun/seriLog.json new file mode 100644 index 0000000..15f0b39 --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/seriLog.json @@ -0,0 +1,12 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { "path": "C:\\УнивСрситСт\\2 курс\\РПП\\AntiAircraftGun\\AntiAircraftGun\\AntiAircraftGun\\bin\\Debug\\net6.0-windows\\Log.txt" } + } + ] + } +}