Skip to content

Commit

Permalink
Merge pull request #108 from infoshareacademy/feature/ja-118-logging-…
Browse files Browse the repository at this point in the history
…configuration

Feature/JA-118 Logging configuration
  • Loading branch information
Zjyslav authored Jun 10, 2024
2 parents 8ccd706 + b2e85fa commit 9827155
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
9 changes: 7 additions & 2 deletions TutorLizard.Web/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Serilog;
using TutorLizard.BusinessLogic.Data;
using TutorLizard.BusinessLogic.Extensions;
using TutorLizard.BusinessLogic.Interfaces.Services;
Expand All @@ -10,6 +11,11 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddSerilog((services, loggerConfiguration) => loggerConfiguration
.ReadFrom.Configuration(builder.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext());

builder.Services.AddControllersWithViews();
builder.Services.AddHttpContextAccessor();
builder.Services.AddRazorPages();
Expand Down Expand Up @@ -39,8 +45,7 @@
{
configuration
.UseSqlServer(builder.Configuration.GetConnectionString("Default"),
b => b.MigrationsAssembly("TutorLizard.Web"))
.LogTo(Console.WriteLine, LogLevel.Information);
b => b.MigrationsAssembly("TutorLizard.Web"));
});

builder.Services.AddTutorLizardDbRepositories<JaszczurContext>();
Expand Down
13 changes: 9 additions & 4 deletions TutorLizard.Web/TutorLizard.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.QuickGrid.EntityFrameworkAdapter" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
<PackageReference Include="Microsoft.AspNetCore.Components.QuickGrid.EntityFrameworkAdapter" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.2" />
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.Seq" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 5 additions & 4 deletions TutorLizard.Web/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Serilog": {
"MinimumLevel": {
"Override": {
"Microsoft.AspNetCore.Routing.EndpointMiddleware": "Information"
}
}
}
}
20 changes: 16 additions & 4 deletions TutorLizard.Web/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
{
"Logging": {
"LogLevel": {
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.Seq" ],
"MinimumLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
"Override": {
"Microsoft.AspNetCore": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}][{SourceContext}] {Message}{NewLine}{Exception}"
}
}
]
},
"AllowedHosts": "*",
"DataJsonFilePaths": {
Expand Down

0 comments on commit 9827155

Please sign in to comment.