From a9253803712dce25a284d0c31f15ca1677dea472 Mon Sep 17 00:00:00 2001 From: victinass Date: Sun, 19 May 2024 10:59:15 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=967?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Battleship/Battleship/Battleship.csproj | 10 +++++++++- .../ListGenericObjects.cs | 2 +- Battleship/Battleship/Program.cs | 20 ++++++++++++++----- Battleship/Battleship/serilog.json | 15 ++++++++++++++ log.txt | 0 5 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 Battleship/Battleship/serilog.json create mode 100644 log.txt diff --git a/Battleship/Battleship/Battleship.csproj b/Battleship/Battleship/Battleship.csproj index 1a78906..ce5a288 100644 --- a/Battleship/Battleship/Battleship.csproj +++ b/Battleship/Battleship/Battleship.csproj @@ -9,8 +9,16 @@ - + + + + + + + + + diff --git a/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs b/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs index e59adfd..05502a6 100644 --- a/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs +++ b/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs @@ -82,4 +82,4 @@ public class ListGenericObjects : ICollectionGenericObjects yield return _collection[i]; } } -} +} \ No newline at end of file diff --git a/Battleship/Battleship/Program.cs b/Battleship/Battleship/Program.cs index e682443..48e655e 100644 --- a/Battleship/Battleship/Program.cs +++ b/Battleship/Battleship/Program.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using NLog.Extensions.Logging; +using Microsoft.Extensions.Configuration; +using Serilog; namespace Battleship { @@ -27,13 +28,22 @@ namespace Battleship /// private static void ConfigureServices(ServiceCollection services) { - services.AddSingleton().AddLogging(option => + string[] path = Directory.GetCurrentDirectory().Split('\\'); + string pathNeed = ""; + for (int i = 0; i < path.Length - 3; i++) + { + pathNeed += path[i] + "\\"; + } + services.AddSingleton() + .AddLogging(option => { option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); + option.AddSerilog(new LoggerConfiguration() + .ReadFrom.Configuration(new ConfigurationBuilder() + .AddJsonFile($"{pathNeed}serilog.json") + .Build()) + .CreateLogger()); }); } - - } } \ No newline at end of file diff --git a/Battleship/Battleship/serilog.json b/Battleship/Battleship/serilog.json new file mode 100644 index 0000000..fa91ef7 --- /dev/null +++ b/Battleship/Battleship/serilog.json @@ -0,0 +1,15 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { "path": "log.log" } + } + ], + "Properties": { + "Application": "Sample" + } + } +} \ No newline at end of file diff --git a/log.txt b/log.txt new file mode 100644 index 0000000..e69de29