From b07df91eed458548083685e5c10bf31628141101 Mon Sep 17 00:00:00 2001 From: Geo7312 Date: Fri, 7 Jun 2024 17:01:37 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=B0=207?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectTrolleybus/ProjectTrolleybus/Program.cs | 18 +++++++++++++++--- .../ProjectTrolleybus/ProjectTrolleybus.csproj | 8 ++++++++ .../ProjectTrolleybus/serilog.json | 15 +++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 ProjectTrolleybus/ProjectTrolleybus/serilog.json diff --git a/ProjectTrolleybus/ProjectTrolleybus/Program.cs b/ProjectTrolleybus/ProjectTrolleybus/Program.cs index 4027b76..b2dec97 100644 --- a/ProjectTrolleybus/ProjectTrolleybus/Program.cs +++ b/ProjectTrolleybus/ProjectTrolleybus/Program.cs @@ -1,7 +1,8 @@ +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using NLog.Extensions.Logging; +using Serilog; namespace ProjectTrolleybus @@ -29,10 +30,21 @@ namespace ProjectTrolleybus /// 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/ProjectTrolleybus/ProjectTrolleybus/ProjectTrolleybus.csproj b/ProjectTrolleybus/ProjectTrolleybus/ProjectTrolleybus.csproj index 5f546b7..349d6dd 100644 --- a/ProjectTrolleybus/ProjectTrolleybus/ProjectTrolleybus.csproj +++ b/ProjectTrolleybus/ProjectTrolleybus/ProjectTrolleybus.csproj @@ -9,8 +9,16 @@ + + + + + + + + diff --git a/ProjectTrolleybus/ProjectTrolleybus/serilog.json b/ProjectTrolleybus/ProjectTrolleybus/serilog.json new file mode 100644 index 0000000..21a6582 --- /dev/null +++ b/ProjectTrolleybus/ProjectTrolleybus/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