Commit eee081ba authored by hasan khaddour's avatar hasan khaddour

configure serilog

parent 3a3ec9b2
...@@ -13,7 +13,13 @@ ...@@ -13,7 +13,13 @@
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="4.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
...@@ -6,6 +6,7 @@ using System; ...@@ -6,6 +6,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Serilog;
namespace PSManagement.Api namespace PSManagement.Api
{ {
...@@ -13,11 +14,17 @@ namespace PSManagement.Api ...@@ -13,11 +14,17 @@ namespace PSManagement.Api
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.WriteTo.File("logs/log-.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
CreateHostBuilder(args).Build().Run(); CreateHostBuilder(args).Build().Run();
} }
public static IHostBuilder CreateHostBuilder(string[] args) => public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args) Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureWebHostDefaults(webBuilder => .ConfigureWebHostDefaults(webBuilder =>
{ {
webBuilder.UseStartup<Startup>(); webBuilder.UseStartup<Startup>();
......
...@@ -13,6 +13,27 @@ ...@@ -13,6 +13,27 @@
"Issuer": "HIAST-PS-Management-Server", "Issuer": "HIAST-PS-Management-Server",
"Audience": "All" "Audience": "All"
}, },
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "Logs/log-.txt",
"rollingInterval": "Day"
}
}
]
},
"ConnectionStrings": { "ConnectionStrings": {
"DefaultConnection": "Data Source=.\\sqlexpress;Initial Catalog=PSManagement ;Integrated Security=True" "DefaultConnection": "Data Source=.\\sqlexpress;Initial Catalog=PSManagement ;Integrated Security=True"
}, },
...@@ -20,6 +41,6 @@ ...@@ -20,6 +41,6 @@
"SyncIntervalInMinutes": 60 "SyncIntervalInMinutes": 60
}, },
"FileServiceSettings": { "FileServiceSettings": {
"AvailableExtension": [".png",".pdf"] "AvailableExtension": [ ".png", ".pdf" ]
} }
} }
...@@ -7,6 +7,7 @@ using MediatR; ...@@ -7,6 +7,7 @@ using MediatR;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Threading; using System.Threading;
using PSManagement.SharedKernel.CQRS.Command; using PSManagement.SharedKernel.CQRS.Command;
using PSManagement.SharedKernel.CQRS.Query;
namespace PSManagement.Application.Behaviors.LoggingBehavior namespace PSManagement.Application.Behaviors.LoggingBehavior
{ {
......
...@@ -7,6 +7,6 @@ using System.Text; ...@@ -7,6 +7,6 @@ using System.Text;
namespace PSManagement.Application.Customers.UseCases.Queries.GetCustomer namespace PSManagement.Application.Customers.UseCases.Queries.GetCustomer
{ {
public record GetCustomerQuery(int CustomerId) : IQuery<Result<CustomerDTO>>; public record GetCustomerQuery(int CustomerId) : ILoggableQuery<Result<CustomerDTO>>;
} }
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.2" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment