diff --git a/Directory.Packages.props b/Directory.Packages.props index dd02beb..ce0da7f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -12,6 +12,13 @@ + + + + + + + diff --git a/src/Somnia.GuestLog/AppSettings.cs b/src/Somnia.GuestLog/AppSettings.cs new file mode 100644 index 0000000..db180e0 --- /dev/null +++ b/src/Somnia.GuestLog/AppSettings.cs @@ -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 +} \ No newline at end of file diff --git a/src/Somnia.GuestLog/Config/log_Config.json b/src/Somnia.GuestLog/Config/log_Config.json new file mode 100644 index 0000000..9b41347 --- /dev/null +++ b/src/Somnia.GuestLog/Config/log_Config.json @@ -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" + } + } + ] + } +} \ No newline at end of file diff --git a/src/Somnia.GuestLog/Program.cs b/src/Somnia.GuestLog/Program.cs index a146770..ffa5bc6 100644 --- a/src/Somnia.GuestLog/Program.cs +++ b/src/Somnia.GuestLog/Program.cs @@ -4,6 +4,9 @@ using Microsoft.AspNetCore.Localization; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; using MudBlazor.Services; +using Serilog; +using Serilog.Extensions.Logging; +using Somnia.GuestLog; using Somnia.GuestLog.Components; using Somnia.GuestLog.Infrastructure; using Somnia.GuestLog.Models.Configuration; @@ -18,6 +21,20 @@ using Somnia.GuestLog.Validators; 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(); + +logger.LogInformation("\n\n\n -------------- Starting {appName} {appVersion} --------------", AppSettings.AppName, AppSettings.AppVersion); + + var connectionStringGuestLog = builder.Configuration.GetConnectionString("DbSomniaGuestLog") ?? throw new InvalidOperationException("Connection string 'DbSomniaGuestLog' not found."); builder.Services.AddDbContextFactory(options => diff --git a/src/Somnia.GuestLog/Somnia.GuestLog.csproj b/src/Somnia.GuestLog/Somnia.GuestLog.csproj index 2746d6d..c789cb9 100644 --- a/src/Somnia.GuestLog/Somnia.GuestLog.csproj +++ b/src/Somnia.GuestLog/Somnia.GuestLog.csproj @@ -12,6 +12,13 @@ + + + + + + + diff --git a/src/Somnia.GuestLog/appsettings.json b/src/Somnia.GuestLog/appsettings.json index f557d9d..90c1da5 100644 --- a/src/Somnia.GuestLog/appsettings.json +++ b/src/Somnia.GuestLog/appsettings.json @@ -2,12 +2,6 @@ "ConnectionStrings": { "DbSomniaGuestLog": "Host=localhost;Port=5432;Username=postgres;Password=P@ssw0rd;Database=SomniaGuestLog" }, - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, "AllowedHosts": "*", "AddressQuery": { "EnableAddressQuery": true,