From 978070b1882698d367a0a27dbff9f67ddb93e9b5 Mon Sep 17 00:00:00 2001 From: insideq Date: Mon, 29 Apr 2024 13:43:21 +0400 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20NL?= =?UTF-8?q?og=20=D0=BD=D0=B0=20Serilog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectExcavator/ProjectExcavator/Program.cs | 17 ++++++++++++++--- .../ProjectExcavator/ProjectExcavator.csproj | 8 ++++++++ ProjectExcavator/ProjectExcavator/serilog.json | 15 +++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 ProjectExcavator/ProjectExcavator/serilog.json diff --git a/ProjectExcavator/ProjectExcavator/Program.cs b/ProjectExcavator/ProjectExcavator/Program.cs index 3e8ae08..9cdfe6c 100644 --- a/ProjectExcavator/ProjectExcavator/Program.cs +++ b/ProjectExcavator/ProjectExcavator/Program.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Configuration; -using NLog.Extensions.Logging; +using Serilog; namespace ProjectExcavator { @@ -29,10 +29,21 @@ namespace ProjectExcavator /// 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()); }); } } diff --git a/ProjectExcavator/ProjectExcavator/ProjectExcavator.csproj b/ProjectExcavator/ProjectExcavator/ProjectExcavator.csproj index 3f8ab34..2788a02 100644 --- a/ProjectExcavator/ProjectExcavator/ProjectExcavator.csproj +++ b/ProjectExcavator/ProjectExcavator/ProjectExcavator.csproj @@ -9,8 +9,16 @@ + + + + + + + + diff --git a/ProjectExcavator/ProjectExcavator/serilog.json b/ProjectExcavator/ProjectExcavator/serilog.json new file mode 100644 index 0000000..a7878e1 --- /dev/null +++ b/ProjectExcavator/ProjectExcavator/serilog.json @@ -0,0 +1,15 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { "path": "log.log" } + } + ], + "Properties": { + "Application": "Sample" + } + } +}