SHA256
Added Serilog for improved logs
- Logs will be shown by console and stored in files.
This commit is contained in:
@@ -12,6 +12,13 @@
|
|||||||
<PackageVersion Include="Grpc.AspNetCore" Version="2.64.0" />
|
<PackageVersion Include="Grpc.AspNetCore" Version="2.64.0" />
|
||||||
<PackageVersion Include="Microsoft.Extensions.Localization" Version="10.0.9" />
|
<PackageVersion Include="Microsoft.Extensions.Localization" Version="10.0.9" />
|
||||||
<PackageVersion Include="MudBlazor" Version="9.4.0" />
|
<PackageVersion Include="MudBlazor" Version="9.4.0" />
|
||||||
|
<PackageVersion Include="Serilog" Version="4.4.0" />
|
||||||
|
<PackageVersion Include="Serilog.Enrichers.Process" Version="3.0.0" />
|
||||||
|
<PackageVersion Include="Serilog.Enrichers.Thread" Version="4.0.0" />
|
||||||
|
<PackageVersion Include="Serilog.Extensions.Hosting" Version="10.0.0" />
|
||||||
|
<PackageVersion Include="Serilog.Settings.Configuration" Version="10.0.1" />
|
||||||
|
<PackageVersion Include="Serilog.Sinks.Console" Version="6.1.1" />
|
||||||
|
<PackageVersion Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="10.0.7" />
|
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="10.0.7" />
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Somnia.GuestLog;
|
||||||
|
|
||||||
|
public static class AppSettings
|
||||||
|
{
|
||||||
|
public const string AppName = "Somnia-GuestLog-dev";
|
||||||
|
|
||||||
|
public const string AppVersion = "v0.0.0-dev"; //2026-09-08
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [
|
||||||
|
"Serilog.Sinks.Console",
|
||||||
|
"Serilog.Sinks.File"
|
||||||
|
],
|
||||||
|
"MinimumLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Override": {
|
||||||
|
"Microsoft": "Warning",
|
||||||
|
"Microsoft.EntityFrameworkCore.Database.Command": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Enrich": [
|
||||||
|
"FromLogContext",
|
||||||
|
"WithThreadId",
|
||||||
|
"WithProcessId"
|
||||||
|
],
|
||||||
|
"Properties": {
|
||||||
|
"ApplicationName": "Somnia-GuestLog"
|
||||||
|
},
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "Console",
|
||||||
|
"Args": {
|
||||||
|
"restrictedToMinimumLevel": "Information"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
// Logs data path
|
||||||
|
"path": "/SomniaGuestLog/logs/log_.log",
|
||||||
|
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{ProcessId}-{ThreadId}] [{Level}] {JobKey}{Message}{NewLine}{Exception}",
|
||||||
|
"rollingInterval": "Day",
|
||||||
|
"rollOnFileSizeLimit": true,
|
||||||
|
"fileSizeLimitBytes": 1073741824,
|
||||||
|
"retainedFileCountLimit": 30,
|
||||||
|
"restrictedToMinimumLevel": "Information"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,9 @@ using Microsoft.AspNetCore.Localization;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||||
using MudBlazor.Services;
|
using MudBlazor.Services;
|
||||||
|
using Serilog;
|
||||||
|
using Serilog.Extensions.Logging;
|
||||||
|
using Somnia.GuestLog;
|
||||||
using Somnia.GuestLog.Components;
|
using Somnia.GuestLog.Components;
|
||||||
using Somnia.GuestLog.Infrastructure;
|
using Somnia.GuestLog.Infrastructure;
|
||||||
using Somnia.GuestLog.Models.Configuration;
|
using Somnia.GuestLog.Models.Configuration;
|
||||||
@@ -18,6 +21,20 @@ using Somnia.GuestLog.Validators;
|
|||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
//Load config files.
|
||||||
|
builder.Configuration.AddJsonFile("Config/log_Config.json", optional: false, reloadOnChange: false);
|
||||||
|
|
||||||
|
//Create and configure Logger (Serilog)
|
||||||
|
var serilog = new LoggerConfiguration()
|
||||||
|
.ReadFrom.Configuration(builder.Configuration)
|
||||||
|
.CreateLogger();
|
||||||
|
builder.Services.AddSerilog(serilog);
|
||||||
|
|
||||||
|
var logger = new SerilogLoggerFactory(serilog).CreateLogger<Program>();
|
||||||
|
|
||||||
|
logger.LogInformation("\n\n\n -------------- Starting {appName} {appVersion} --------------", AppSettings.AppName, AppSettings.AppVersion);
|
||||||
|
|
||||||
|
|
||||||
var connectionStringGuestLog = builder.Configuration.GetConnectionString("DbSomniaGuestLog")
|
var connectionStringGuestLog = builder.Configuration.GetConnectionString("DbSomniaGuestLog")
|
||||||
?? throw new InvalidOperationException("Connection string 'DbSomniaGuestLog' not found.");
|
?? throw new InvalidOperationException("Connection string 'DbSomniaGuestLog' not found.");
|
||||||
builder.Services.AddDbContextFactory<GuestLogContext>(options =>
|
builder.Services.AddDbContextFactory<GuestLogContext>(options =>
|
||||||
|
|||||||
@@ -12,6 +12,13 @@
|
|||||||
<PackageReference Include="FluentStorage.AWS" />
|
<PackageReference Include="FluentStorage.AWS" />
|
||||||
<PackageReference Include="FluentValidation" />
|
<PackageReference Include="FluentValidation" />
|
||||||
<PackageReference Include="MudBlazor" />
|
<PackageReference Include="MudBlazor" />
|
||||||
|
<PackageReference Include="Serilog" />
|
||||||
|
<PackageReference Include="Serilog.Enrichers.Process" />
|
||||||
|
<PackageReference Include="Serilog.Enrichers.Thread" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Hosting" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.Console" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -2,12 +2,6 @@
|
|||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"DbSomniaGuestLog": "Host=localhost;Port=5432;Username=postgres;Password=P@ssw0rd;Database=SomniaGuestLog"
|
"DbSomniaGuestLog": "Host=localhost;Port=5432;Username=postgres;Password=P@ssw0rd;Database=SomniaGuestLog"
|
||||||
},
|
},
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"AddressQuery": {
|
"AddressQuery": {
|
||||||
"EnableAddressQuery": true,
|
"EnableAddressQuery": true,
|
||||||
|
|||||||
Reference in New Issue
Block a user