From c34c2b42a00031cce2e7d17db3a3d4398bc3905d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=BC=D0=B0=20=D0=9F=D0=B5=D1=80=D0=BC=D1=8F?= =?UTF-8?q?=D0=BA=D0=BE=D0=B2?= Date: Mon, 6 May 2024 15:47:54 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AccordionBus/AccordionBus/AccordionBus.csproj | 3 +++ AccordionBus/AccordionBus/Program.cs | 18 ++++++++++-------- AccordionBus/AccordionBus/serilog.json | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 AccordionBus/AccordionBus/serilog.json diff --git a/AccordionBus/AccordionBus/AccordionBus.csproj b/AccordionBus/AccordionBus/AccordionBus.csproj index f4009d4..f29b6a2 100644 --- a/AccordionBus/AccordionBus/AccordionBus.csproj +++ b/AccordionBus/AccordionBus/AccordionBus.csproj @@ -9,6 +9,9 @@ + + + diff --git a/AccordionBus/AccordionBus/Program.cs b/AccordionBus/AccordionBus/Program.cs index 528134f..c6856c2 100644 --- a/AccordionBus/AccordionBus/Program.cs +++ b/AccordionBus/AccordionBus/Program.cs @@ -1,6 +1,8 @@ +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Serilog; +using Serilog.Events; namespace AccordionBus { @@ -24,14 +26,14 @@ namespace AccordionBus private static void ConfigureServices(ServiceCollection services) { services.AddSingleton() - .AddLogging(option => option.AddSerilog(dispose: true)); - - Log.Logger = new LoggerConfiguration() - .MinimumLevel.Debug() - .WriteTo.File("C:\\my\\ 1 2\\ \\log.txt") - .CreateLogger(); + .AddLogging(option => { + option.SetMinimumLevel(LogLevel.Debug); + option.AddSerilog(new LoggerConfiguration() + .ReadFrom.Configuration(new ConfigurationBuilder() + .AddJsonFile("C:\\my\\ 1 2\\ \\simple\\AccordionBus\\AccordionBus\\serilog.json") + .Build()) + .CreateLogger()); + }); } - - } } \ No newline at end of file diff --git a/AccordionBus/AccordionBus/serilog.json b/AccordionBus/AccordionBus/serilog.json new file mode 100644 index 0000000..69abef3 --- /dev/null +++ b/AccordionBus/AccordionBus/serilog.json @@ -0,0 +1,18 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "C:\\my\\курс 1 сим 2\\для ООП\\log.txt", + "outputTemplate": "[{Level:u}] [{Timestamp:yyyy-MM-dd HH:mm:ss.ffff}] {Message:1j}{NewLine}{Exception}" + } + } + ], + "Properties": { + "Application": "Sample" + } + } +} \ No newline at end of file