начало 2 лабы
This commit is contained in:
parent
88cb562e5d
commit
6119b3431e
@ -1,6 +1,10 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using ProjectPeopleTransportation.Repositories;
|
using ProjectPeopleTransportation.Repositories;
|
||||||
using ProjectPeopleTransportation.Repositories.Implementations;
|
using ProjectPeopleTransportation.Repositories.Implementations;
|
||||||
|
using Serilog;
|
||||||
using Unity;
|
using Unity;
|
||||||
|
using Unity.Microsoft.Logging;
|
||||||
|
|
||||||
namespace ProjectPeopleTransportation
|
namespace ProjectPeopleTransportation
|
||||||
{
|
{
|
||||||
@ -22,13 +26,28 @@ namespace ProjectPeopleTransportation
|
|||||||
{
|
{
|
||||||
var container = new UnityContainer();
|
var container = new UnityContainer();
|
||||||
|
|
||||||
|
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
|
||||||
|
|
||||||
container.RegisterType<IBusRepository, BusRepository>();
|
container.RegisterType<IBusRepository, BusRepository>();
|
||||||
container.RegisterType<IEmployeeRepository, EmployeeRepository>();
|
container.RegisterType<IEmployeeRepository, EmployeeRepository>();
|
||||||
container.RegisterType<IBusCheckRepository, BusCheckRepository>();
|
container.RegisterType<IBusCheckRepository, BusCheckRepository>();
|
||||||
container.RegisterType<IRouteListRepository, RouteListRepository>();
|
container.RegisterType<IRouteListRepository, RouteListRepository>();
|
||||||
container.RegisterType<IStartingShiftRepository, StartingShiftRepository>();
|
container.RegisterType<IStartingShiftRepository, StartingShiftRepository>();
|
||||||
|
container.RegisterType<IConnectionString, ConnectionString>();
|
||||||
|
|
||||||
return container;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,7 +9,16 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="Serilog" Version="4.1.0" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||||
<PackageReference Include="Unity" Version="5.11.10" />
|
<PackageReference Include="Unity" Version="5.11.10" />
|
||||||
|
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -27,4 +36,10 @@
|
|||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="appsettings.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -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; }
|
||||||
|
}
|
@ -1,12 +1,26 @@
|
|||||||
using ProjectPeopleTransportation.Entities;
|
using ProjectPeopleTransportation.Entities;
|
||||||
using ProjectPeopleTransportation.Entities.Enums;
|
using ProjectPeopleTransportation.Entities.Enums;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace ProjectPeopleTransportation.Repositories.Implementations;
|
namespace ProjectPeopleTransportation.Repositories.Implementations;
|
||||||
|
|
||||||
public class BusRepository : IBusRepository
|
public class BusRepository : IBusRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
|
||||||
|
private readonly ILogger<BusRepository> _logger;
|
||||||
|
|
||||||
|
public BusRepository(IConnectionString connectionString, ILogger<BusRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
public void CreateBus(Bus bus)
|
public void CreateBus(Bus bus)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(bus));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteBus(int id)
|
public void DeleteBus(int id)
|
||||||
|
@ -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 => "";
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [ "Serilog.Sinks.File" ],
|
||||||
|
"MinimumLevel": "Debug",
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "Logs/log.txt",
|
||||||
|
"rollingInterval": "Day"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user