From 8e7d51114470ad42d5816b432ff628944e175f70 Mon Sep 17 00:00:00 2001 From: Arslan Date: Mon, 29 Apr 2024 09:31:10 +0400 Subject: [PATCH] =?UTF-8?q?7=20=D0=BB=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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectFighterJet/Program.cs | 23 ++++++++++++++++------ ProjectFighterJet/ProjectFighterJet.csproj | 7 +++++++ ProjectFighterJet/nlog.config | 3 --- ProjectFighterJet/serilog.json | 15 ++++++++++++++ 4 files changed, 39 insertions(+), 9 deletions(-) delete mode 100644 ProjectFighterJet/nlog.config create mode 100644 ProjectFighterJet/serilog.json diff --git a/ProjectFighterJet/Program.cs b/ProjectFighterJet/Program.cs index 7059418..2fc5878 100644 --- a/ProjectFighterJet/Program.cs +++ b/ProjectFighterJet/Program.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Serilog; using Microsoft.Extensions.Configuration; -using NLog.Extensions.Logging; namespace ProjectFighterJet { @@ -25,12 +25,23 @@ namespace ProjectFighterJet } private static void ConfigureServices(ServiceCollection services) { + + 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"); - }); + .AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddSerilog(new LoggerConfiguration() + .ReadFrom.Configuration(new ConfigurationBuilder() + .AddJsonFile($"{pathNeed}serilog.json") + .Build()) + .CreateLogger()); + }); } } } \ No newline at end of file diff --git a/ProjectFighterJet/ProjectFighterJet.csproj b/ProjectFighterJet/ProjectFighterJet.csproj index ebbf751..b4bc593 100644 --- a/ProjectFighterJet/ProjectFighterJet.csproj +++ b/ProjectFighterJet/ProjectFighterJet.csproj @@ -11,9 +11,16 @@ + + + + + + + diff --git a/ProjectFighterJet/nlog.config b/ProjectFighterJet/nlog.config deleted file mode 100644 index 49cc43e..0000000 --- a/ProjectFighterJet/nlog.config +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/ProjectFighterJet/serilog.json b/ProjectFighterJet/serilog.json new file mode 100644 index 0000000..a7878e1 --- /dev/null +++ b/ProjectFighterJet/serilog.json @@ -0,0 +1,15 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { "path": "log.log" } + } + ], + "Properties": { + "Application": "Sample" + } + } +}