Added Serilog
- Configuration is defined in appsettings.json - Uses console and file sinks
This commit is contained in:
parent
ed94081826
commit
7df4ab72b8
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -9,6 +9,8 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Markdig" Version="0.35.0" />
|
||||
<PackageReference Include="Serilog" Version="3.1.1" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
"DetailedErrors": true,
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Default": "Debug",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
|
||||
@ -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" } }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user