From ef5e2815c51ab1ae5518317181cb57ce4b1d4b95 Mon Sep 17 00:00:00 2001 From: Pyro <732603@gmail.com> Date: Fri, 29 Nov 2024 09:16:11 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B5=D0=BE=D0=B1=D1=85=D0=BE?= =?UTF-8?q?=D0=B4=D0=B8=D0=BC=D1=8B=D1=85=20=D0=B7=D0=B0=D0=B2=D0=B8=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D0=B5=D0=B9=20=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B0=20=D0=BB=D0=BE?= =?UTF-8?q?=D0=B3=D0=B3=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectConfectionaryFactory/Program.cs | 22 +++++++++++++++++++ .../ProjectConfectionaryFactory.csproj | 17 ++++++++++++++ .../Repositories/IConnectionString.cs | 6 +++++ .../appsettings.json | 15 +++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 ProjectConfectionaryFactory/ProjectConfectionaryFactory/Repositories/IConnectionString.cs create mode 100644 ProjectConfectionaryFactory/ProjectConfectionaryFactory/appsettings.json diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Program.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Program.cs index 7f0fa7f..2262b79 100644 --- a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Program.cs +++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Program.cs @@ -2,6 +2,10 @@ using Unity.Lifetime; using Unity; using ProjectConfectionaryFactory.Repositories; using ProjectConfectionaryFactory.Repositories.Implementations; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using Serilog; +using Unity.Microsoft.Logging; namespace ProjectConfectionaryFactory { @@ -22,13 +26,31 @@ namespace ProjectConfectionaryFactory private static IUnityContainer CreateContainer() { var container = new UnityContainer(); + + container.AddExtension(new LoggingExtension(CreateLoggerFactory())); + container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); + + container.RegisterType(new SingletonLifetimeManager()); + return container; } + + private static LoggerFactory CreateLoggerFactory() + { + var loggerFactory = new LoggerFactory(); + loggerFactory.AddSerilog(new LoggerConfiguration() + .ReadFrom.Configuration(new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json") + .Build()) + .CreateLogger()); + return loggerFactory; + } } } \ No newline at end of file diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/ProjectConfectionaryFactory.csproj b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/ProjectConfectionaryFactory.csproj index accbdf0..8fa1cd1 100644 --- a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/ProjectConfectionaryFactory.csproj +++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/ProjectConfectionaryFactory.csproj @@ -9,7 +9,18 @@ + + + + + + + + + + + @@ -27,4 +38,10 @@ + + + PreserveNewest + + + \ No newline at end of file diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Repositories/IConnectionString.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Repositories/IConnectionString.cs new file mode 100644 index 0000000..3a8ab9f --- /dev/null +++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Repositories/IConnectionString.cs @@ -0,0 +1,6 @@ +namespace ProjectConfectionaryFactory.Repositories; + +public interface IConnectionString +{ + public string ConnectionString { get; } +} diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/appsettings.json b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/appsettings.json new file mode 100644 index 0000000..87b332f --- /dev/null +++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/appsettings.json @@ -0,0 +1,15 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "Logs/confectionary_log.txt", + "rollingInterval": "Day" + } + } + ] + } +} \ No newline at end of file