serilog-web / classic-webapi

[Discontinued] ASP.NET WebAPI support for SerilogWeb.Classic
Apache License 2.0
15 stars 7 forks source link
asp-net asp-net-webapi serilog serilog-enricher serilog-extension

SerilogWeb.Classic.WebApi Build status

Deprecation notice: this package is no longer maintained. The world has moved on to ASP.NET Core. Take a look at Serilog.AspNetCore instead!

ASP.NET WebAPI support for SerilogWeb.Classic.

Package - SerilogWeb.Classic.WebApi | Platforms - .NET 4.5

This package is designed for full framework ASP.NET applications. For ASP.NET Core, have a look at Serilog.AspNetCore

This package is used in conjunction with SerilogWeb.Classic and adds :

Enrichers

The following enrichers are available as extension methods from the LoggerConfiguration.Enrich API:

Usage :

var log = new LoggerConfiguration()
    .WriteTo.Console()
    .Enrich.WithWebApiRouteTemplate()
    .Enrich.WithWebApiActionName()
    .CreateLogger();

To override the property name of the added property:

var log = new LoggerConfiguration()
    .WriteTo.Console()
    .Enrich.WithWebApiRouteTemplate("RouteTemplate")
    .CreateLogger();

Enrichers can also be defined in a configuration file by using Serilog.Settings.AppSettings as follows:

<appSettings>
    <add key="serilog:using:SerilogWeb.Classic.WebApi" value="SerilogWeb.Classic.WebApi"/>
    <add key="serilog:enrich:WithWebApiActionName" />
    <add key="serilog:enrich:WithWebApiControllerName" />
    <add key="serilog:enrich:WithWebApiRouteData" />
    <add key="serilog:enrich:WithWebApiRouteTemplate" />
</appSettings>