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