Skip to content
ASP.NET WebAPI support for SerilogWeb.Classic
C# PowerShell ASP
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
assets A few tweaks to match the SerilogWeb.Classic project structure, so we… Jan 19, 2016
src/SerilogWeb.Classic.WebApi
test/SerilogWeb.Classic.WebApi.Test Update SerilogWeb.Classic version to v5.0 Feb 28, 2019
.gitattributes A few tweaks to match the SerilogWeb.Classic project structure, so we… Jan 19, 2016
.gitignore Initial commit Jan 12, 2016
Build.ps1 A few tweaks to match the SerilogWeb.Classic project structure, so we… Jan 19, 2016
CHANGES.md A few tweaks to match the SerilogWeb.Classic project structure, so we… Jan 19, 2016
LICENSE Initial commit Jan 12, 2016
README.md Fix AppVeyor build May 30, 2018
appveyor.yml Do not build on tags [skip ci] Mar 25, 2019
serilog-web-classic-webapi.sln Try to fix broken build for #6 Dec 1, 2017

README.md

SerilogWeb.Classic.WebApi Build status

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 :

  • support for logging WebAPI exceptions with Serilog
  • Web API specific enrichers

Enrichers

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

  • WithWebApiActionName : adds a property WebApiAction containing the name of the Action being executed in the Web API Controller
  • WithWebApiControllerName : adds a property WebApiController containing the name of the Controller in which a Web API Action has executed
  • WithWebApiRouteData : adds a property WebApiRouteData containing the dictionary of the RouteData
  • WithWebApiRouteTemplate : adds a property WebApiRouteTemplate containing the route template selected by Web API routing

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>
You can’t perform that action at this time.