Serilog.Extras 1.0.6

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Serilog.Extras --version 1.0.6
NuGet\Install-Package Serilog.Extras -Version 1.0.6
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Serilog.Extras" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Serilog.Extras --version 1.0.6
#r "nuget: Serilog.Extras, 1.0.6"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Serilog.Extras as a Cake Addin
#addin nuget:?package=Serilog.Extras&version=1.0.6

// Install Serilog.Extras as a Cake Tool
#tool nuget:?package=Serilog.Extras&version=1.0.6

Overview

This package contains two enrichers and a handler to add request logging but excluding health checks. The latter part is heavily based on Andrew Lock's blog entry.

Enrichers

Version Number

This takes the environment variable VERSION_NUMBER and, if presents, logs the value to a VersionNumber field. If not present, N/A is logged.

Usage

Add WithVersionNumber to the Enrich array in the Serilog configuration node.

Deployment Environment

This takes the environment variable ASPNETCORE_ENVIRONMENT and, if presents, logs the value to a DeploymentEnvironment field. If not present, N/A is logged.

Usage

Add WithDeploymentEnvironment to the Enrich array in the Serilog configuration node.

Request Logging Without Health Checks

This is the same as the standard app.UseSerilogRequestLogging() call but filters out health checks. This is heavily based on Andrew Lock's blog entry.

Usage

Use app.UseSerilogRequestLoggingWithoutHealthChecks() (instead of app.UseSerilogRequestLogging())

General Log Handler

The following is an example Program.cs and includes Swagger on the assumption this is for an API - simply remove if not required. It's assumed your logging is configured in a file called serilog.json.

using Serilog;
using Serilog.Extras;

AppDomain.CurrentDomain.UnhandledException += GeneralLogHandler.AppUnhandledException;

using (var logger = GeneralLogHandler.BuildSerilog())
{
    Log.Information("Application starting...");

    try
    {
        var builder = WebApplication.CreateBuilder(args);

        // load configuration
        builder.Configuration.AddEnvironmentVariables();

        // Add services to the container.
        // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
        builder.Services.AddEndpointsApiExplorer();
        builder.Services.AddSwaggerGen();

        builder.Host.UseSerilog();

        var app = builder.Build();

        // Configure the HTTP request pipeline.
        if (app.Environment.IsDevelopment())
        {
        }

        app.UseSwagger();
        app.UseSwaggerUI(c => { c.SwaggerEndpoint("../swagger/v1/swagger.json", "API v1.0"); });

        app.UseSerilogRequestLogging();

        app.MapEndpoints();

        app.Run();

    }
    catch (Exception e)
    {
        GeneralLogHandler.UnhandledExceptions(e);
    }
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.8-beta 282 12/1/2023
1.0.7-beta 147 5/11/2022
1.0.6 1,928 4/1/2022
1.0.3 471 2/7/2022