From 0942dd8be33d27901f04a04977881f05422b28c4 Mon Sep 17 00:00:00 2001 From: Baryshev Dmitry Date: Sat, 30 Nov 2024 16:03:41 +0400 Subject: [PATCH] a little work --- ProjectGarage/Program.cs | 18 ++++++++++++++++++ ProjectGarage/ProjectGarage.csproj | 3 ++- .../Implementations/ConnectionString.cs | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ProjectGarage/Program.cs b/ProjectGarage/Program.cs index 559f30f..b6f110f 100644 --- a/ProjectGarage/Program.cs +++ b/ProjectGarage/Program.cs @@ -1,6 +1,11 @@ using ProjectGarage.Repositories; using ProjectGarage.Repositories.Implementations; +using Unity.Lifetime; using Unity; +using Unity.Microsoft.Logging; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using Serilog; namespace ProjectGarage { @@ -21,6 +26,7 @@ namespace ProjectGarage private static IUnityContainer CreateContainer() { var container = new UnityContainer(); + container.AddExtension(new LoggingExtension(CreateLoggerFactory())); container.RegisterType(); container.RegisterType(); @@ -33,5 +39,17 @@ namespace ProjectGarage 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/ProjectGarage/ProjectGarage.csproj b/ProjectGarage/ProjectGarage.csproj index 166436b..19ad3ed 100644 --- a/ProjectGarage/ProjectGarage.csproj +++ b/ProjectGarage/ProjectGarage.csproj @@ -13,7 +13,8 @@ - + + diff --git a/ProjectGarage/Repositories/Implementations/ConnectionString.cs b/ProjectGarage/Repositories/Implementations/ConnectionString.cs index 152a14c..938ce31 100644 --- a/ProjectGarage/Repositories/Implementations/ConnectionString.cs +++ b/ProjectGarage/Repositories/Implementations/ConnectionString.cs @@ -8,5 +8,5 @@ namespace ProjectGarage.Repositories.Implementations; public class ConnectionString : IConnectionString { - string IConnectionString.ConnectionString => ""; + string IConnectionString.ConnectionString => "Host=localhost;Port=5432;Username=postgres;Password=postgres;Database=postgres"; }