SyntaxCircus.AspNetCore.Serilog
0.1.2
See the version list below for details.
dotnet add package SyntaxCircus.AspNetCore.Serilog --version 0.1.2
NuGet\Install-Package SyntaxCircus.AspNetCore.Serilog -Version 0.1.2
<PackageReference Include="SyntaxCircus.AspNetCore.Serilog" Version="0.1.2" />
<PackageVersion Include="SyntaxCircus.AspNetCore.Serilog" Version="0.1.2" />
<PackageReference Include="SyntaxCircus.AspNetCore.Serilog" />
paket add SyntaxCircus.AspNetCore.Serilog --version 0.1.2
#r "nuget: SyntaxCircus.AspNetCore.Serilog, 0.1.2"
#:package SyntaxCircus.AspNetCore.Serilog@0.1.2
#addin nuget:?package=SyntaxCircus.AspNetCore.Serilog&version=0.1.2
#tool nuget:?package=SyntaxCircus.AspNetCore.Serilog&version=0.1.2
SyntaxCircus.AspNetCore.Serilog
A standard Serilog bootstrap for both ASP.NET Core hosts and worker services, with an optional file-sink path resolver. Standalone on purpose — pulled out of SyntaxCircus.AspNetCore.Common so that package stays free of the Serilog dependency for consumers who don't want it.
No support guaranteed. Published as-is and maintained on a best-effort basis. Issues and PRs are welcome, but there's no SLA — fork it or vendor what you need if that's not enough.
Usage
var builder = WebApplication.CreateBuilder(args); // or Host.CreateApplicationBuilder(args) for a worker service
builder.AddStandardSerilog();
var app = builder.Build();
app.UseSerilogRequestLogging(); // ASP.NET Core hosts only
Sets up a console-only bootstrap logger active until the host finishes building, then reconfigures from appsettings/DI services (ReadFrom.Configuration + ReadFrom.Services + Enrich.FromLogContext). Uses Services.AddSerilog(...) rather than Host.UseSerilog(...) so it works on both WebApplicationBuilder and a plain worker-service HostApplicationBuilder — AddStandardSerilog targets the shared IHostApplicationBuilder interface both implement.
Optional file logging
builder.AddStandardSerilog(fileLogging =>
{
fileLogging.Enabled = true;
fileLogging.Path = "logs/log-.txt"; // optional — relative to content root; omit for the LocalAppData default
fileLogging.RollingInterval = RollingInterval.Day;
fileLogging.RetainedFileCountLimit = 14; // optional — omit (default null) to retain all rolled files
});
When Path is omitted, logs go to %LocalAppData%/{ApplicationName}/logs/log-.txt.
RetainedFileCountLimit matches Serilog's own File sink default: null retains every rolled
file indefinitely; set it to cap on-disk retention (oldest files beyond the limit are deleted
as new ones roll).
Additional enrichers
builder.AddStandardSerilog(configureEnrichment: cfg => cfg
.Enrich.WithMachineName()
.Enrich.WithEnvironmentName());
configureEnrichment is invoked after Enrich.FromLogContext() and before the file sink (if any) is wired up — use it to layer on any enrichers AddStandardSerilog doesn't add by default.
Contributing
Issues and pull requests are welcome:
- Keep changes focused, with a clear description of the behavior change.
- Match the existing code style (see
.editorconfig). - Call out any breaking changes to the public API in your PR description.
License
MIT — see LICENSE.txt.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Serilog.AspNetCore (>= 10.0.0)
- Serilog.Sinks.Console (>= 6.1.1)
- Serilog.Sinks.File (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.