From 12f0622d683a55cba1eebd57efbd2e33921bf46d Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 17 Nov 2022 15:11:22 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=BD=D0=B0=20Serilog.=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE?= =?UTF-8?q?=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=20json.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/Airbus.csproj | 7 +++++ Airbus/Airbus/Program.cs | 16 ++++++++++-- Airbus/Airbus/appsettings.json | 48 ++++++++++++++++++++++++++++++++++ Airbus/Airbus/nlog.config | 15 ----------- 4 files changed, 69 insertions(+), 17 deletions(-) create mode 100644 Airbus/Airbus/appsettings.json delete mode 100644 Airbus/Airbus/nlog.config diff --git a/Airbus/Airbus/Airbus.csproj b/Airbus/Airbus/Airbus.csproj index c22bcea..8c229c9 100644 --- a/Airbus/Airbus/Airbus.csproj +++ b/Airbus/Airbus/Airbus.csproj @@ -39,11 +39,18 @@ + + + + + + + \ No newline at end of file diff --git a/Airbus/Airbus/Program.cs b/Airbus/Airbus/Program.cs index 5dc32b1..16904b8 100644 --- a/Airbus/Airbus/Program.cs +++ b/Airbus/Airbus/Program.cs @@ -1,6 +1,9 @@ +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using NLog.Extensions.Logging; +using Serilog; +using Serilog.Extensions.Logging; +using System; namespace Airbus { @@ -30,8 +33,17 @@ namespace Airbus services.AddSingleton() .AddLogging(option => { + var configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile(path: "C:\\Users\\Programmist73\\Desktop\\Ïðàêòèêà\\2-é êóðñ\\ÐÏÏ\\Base\\PIbd-21_Eliseev_E.E._Airbus_Base\\Airbus\\Airbus\\appsettings.json", optional: false, reloadOnChange: true) + .Build(); + + var logger = new LoggerConfiguration() + .ReadFrom.Configuration(configuration) + .CreateLogger(); + option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); + option.AddSerilog(logger); }); } } diff --git a/Airbus/Airbus/appsettings.json b/Airbus/Airbus/appsettings.json new file mode 100644 index 0000000..bb6390d --- /dev/null +++ b/Airbus/Airbus/appsettings.json @@ -0,0 +1,48 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Information", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "Logs/log_.log", + "rollingInterval": "Day", + "outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}" + } + } + ], + "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], + "Destructure": [ + { + "Name": "ByTransforming", + "Args": { + "returnType": "Plane.EntityAirbus", + "transformation": "r => new { BodyColor = r.BodyColor.Name, r.Speed, r.Weight }" + } + }, + { + "Name": "ByTransforming", + "Args": { + "returnType": "Plane.EntitySuperAirbus", + "transformation": "r => new { BodyColor = r.BodyColor.Name, DopColor = r.DopColor.Name, r.HasСompartment, r.HasEngine, r.Speed, r.Weight }" + } + }, + { + "Name": "ToMaximumDepth", + "Args": { "maximumDestructuringDepth": 4 } + }, + { + "Name": "ToMaximumStringLength", + "Args": { "maximumStringLength": 100 } + }, + { + "Name": "ToMaximumCollectionCount", + "Args": { "maximumCollectionCount": 10 } + } + ], + "Properties": { + "Application": "Airbus" + } + } +} \ No newline at end of file diff --git a/Airbus/Airbus/nlog.config b/Airbus/Airbus/nlog.config deleted file mode 100644 index 02f005b..0000000 --- a/Airbus/Airbus/nlog.config +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file