From 6119b3431eff36452a9111d6ded0cebddf7a44fa Mon Sep 17 00:00:00 2001 From: cyxaruk Date: Mon, 18 Nov 2024 13:57:41 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=202=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectPeopleTransportation/Program.cs | 19 +++++++++++++++++++ .../ProjectPeopleTransportation.csproj | 15 +++++++++++++++ .../Repositories/IConnectionString.cs | 12 ++++++++++++ .../Implementations/BusRepository.cs | 14 ++++++++++++++ .../Implementations/ConnectionString.cs | 12 ++++++++++++ .../appsettings.json | 15 +++++++++++++++ 6 files changed, 87 insertions(+) create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Repositories/IConnectionString.cs create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Repositories/Implementations/ConnectionString.cs create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/appsettings.json diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Program.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Program.cs index 20fbfe2..a655700 100644 --- a/ProjectPeopleTransportation/ProjectPeopleTransportation/Program.cs +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Program.cs @@ -1,6 +1,10 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; using ProjectPeopleTransportation.Repositories; using ProjectPeopleTransportation.Repositories.Implementations; +using Serilog; using Unity; +using Unity.Microsoft.Logging; namespace ProjectPeopleTransportation { @@ -22,13 +26,28 @@ namespace ProjectPeopleTransportation { var container = new UnityContainer(); + container.AddExtension(new LoggingExtension(CreateLoggerFactory())); + container.RegisterType(); container.RegisterType(); container.RegisterType(); container.RegisterType(); container.RegisterType(); + container.RegisterType(); 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/ProjectPeopleTransportation/ProjectPeopleTransportation/ProjectPeopleTransportation.csproj b/ProjectPeopleTransportation/ProjectPeopleTransportation/ProjectPeopleTransportation.csproj index accbdf0..ef96adf 100644 --- a/ProjectPeopleTransportation/ProjectPeopleTransportation/ProjectPeopleTransportation.csproj +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/ProjectPeopleTransportation.csproj @@ -9,7 +9,16 @@ + + + + + + + + + @@ -27,4 +36,10 @@ + + + PreserveNewest + + + \ No newline at end of file diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Repositories/IConnectionString.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Repositories/IConnectionString.cs new file mode 100644 index 0000000..01894df --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Repositories/IConnectionString.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectPeopleTransportation.Repositories; + +public interface IConnectionString +{ + public string ConnectionString { get; } +} diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Repositories/Implementations/BusRepository.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Repositories/Implementations/BusRepository.cs index 56c9708..35bfe27 100644 --- a/ProjectPeopleTransportation/ProjectPeopleTransportation/Repositories/Implementations/BusRepository.cs +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Repositories/Implementations/BusRepository.cs @@ -1,12 +1,26 @@ using ProjectPeopleTransportation.Entities; using ProjectPeopleTransportation.Entities.Enums; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; namespace ProjectPeopleTransportation.Repositories.Implementations; public class BusRepository : IBusRepository { + private readonly IConnectionString _connectionString; + + private readonly ILogger _logger; + + public BusRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + public void CreateBus(Bus bus) { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(bus)); } public void DeleteBus(int id) diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Repositories/Implementations/ConnectionString.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Repositories/Implementations/ConnectionString.cs new file mode 100644 index 0000000..54bea12 --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Repositories/Implementations/ConnectionString.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectPeopleTransportation.Repositories.Implementations; + +internal class ConnectionString : IConnectionString +{ + string IConnectionString.ConnectionString => ""; +} diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/appsettings.json b/ProjectPeopleTransportation/ProjectPeopleTransportation/appsettings.json new file mode 100644 index 0000000..2f734b4 --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/appsettings.json @@ -0,0 +1,15 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "Logs/log.txt", + "rollingInterval": "Day" + } + } + ] + } +} \ No newline at end of file