diff --git a/WretchedMachines/Pages/Index.cshtml.cs b/WretchedMachines/Pages/Index.cshtml.cs index b03363a..dcc751f 100644 --- a/WretchedMachines/Pages/Index.cshtml.cs +++ b/WretchedMachines/Pages/Index.cshtml.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using Serilog; namespace WretchedMachines.Pages; @@ -14,6 +15,6 @@ public class IndexModel : PageModel public void OnGet() { - + Log.Information("Test"); } } diff --git a/WretchedMachines/Pages/Privacy.cshtml.cs b/WretchedMachines/Pages/Privacy.cshtml.cs index 631ca1f..c961dea 100644 --- a/WretchedMachines/Pages/Privacy.cshtml.cs +++ b/WretchedMachines/Pages/Privacy.cshtml.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using Serilog; namespace WretchedMachines.Pages; @@ -14,6 +15,7 @@ public class PrivacyModel : PageModel public void OnGet() { + Log.Information("Test"); } } diff --git a/WretchedMachines/Program.cs b/WretchedMachines/Program.cs index bc275e4..7ad5baf 100644 --- a/WretchedMachines/Program.cs +++ b/WretchedMachines/Program.cs @@ -1,10 +1,18 @@ +using Serilog; + + var builder = WebApplication.CreateBuilder(args); +Log.Logger = new LoggerConfiguration() + .ReadFrom.Configuration(builder.Configuration) + .CreateLogger(); + +Log.Information("Starting"); +builder.Host.UseSerilog(); // Add services to the container. builder.Services.AddRazorPages(); - +// builder.Host.UseSerilog(); var app = builder.Build(); - // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { @@ -13,6 +21,7 @@ if (!app.Environment.IsDevelopment()) app.UseHsts(); } +app.UseSerilogRequestLogging(); app.UseHttpsRedirection(); app.UseStaticFiles(); diff --git a/WretchedMachines/WretchedMachines.csproj b/WretchedMachines/WretchedMachines.csproj index bd1b97d..8a3559e 100644 --- a/WretchedMachines/WretchedMachines.csproj +++ b/WretchedMachines/WretchedMachines.csproj @@ -9,6 +9,8 @@ + + diff --git a/WretchedMachines/appsettings.Development.json b/WretchedMachines/appsettings.Development.json index 770d3e9..b939533 100644 --- a/WretchedMachines/appsettings.Development.json +++ b/WretchedMachines/appsettings.Development.json @@ -2,7 +2,7 @@ "DetailedErrors": true, "Logging": { "LogLevel": { - "Default": "Information", + "Default": "Debug", "Microsoft.AspNetCore": "Warning" } } diff --git a/WretchedMachines/appsettings.json b/WretchedMachines/appsettings.json index 10f68b8..71b318e 100644 --- a/WretchedMachines/appsettings.json +++ b/WretchedMachines/appsettings.json @@ -5,5 +5,15 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "ConnectionStrings": { + "Default": "" + }, + "Serilog": { + "Using": ["Serilog.Sinks.Console", "Serilog.Sinks.File"], + "WriteTo": [ + {"Name": "Console"}, + { "Name": "File", "Args": { "path": "logs/log-.txt", "rollingInterval": "Day" } } + ] + } }