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 MVC support for SerilogWeb.Classic.
Package - SerilogWeb.Classic.Mvc | 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 ASP.NET MVC specific enrichers.
The following enrichers are available as extension methods from the LoggerConfiguration.Enrich
API:
- WithMvcActionName : adds a property
MvcAction
containing the name of the Action being executed in the MVC Controller - WithMvcControllerName : adds a property
MvcController
containing the name of the Controller in which a MVC Action has executed - WithMvcRouteData : adds a property
MvcRouteData
containing the dictionary of the RouteData - WithMvcRouteTemplate : adds a property
MvcRouteTemplate
containing the route template selected by Mvc routing
Usage :
var log = new LoggerConfiguration()
.WriteTo.Console()
.Enrich.WithMvcRouteTemplate()
.Enrich.WithMvcActionName()
.CreateLogger();
To override the property name of the added property:
var log = new LoggerConfiguration()
.WriteTo.Console()
.Enrich.WithMvcRouteTemplate("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.Mvc" value="SerilogWeb.Classic.Mvc"/>
<add key="serilog:enrich:WithMvcActionName"/>
<add key="serilog:enrich:WithMvcControllerName"/>
<add key="serilog:enrich:WithMvcRouteData"/>
<add key="serilog:enrich:WithMvcRouteTemplate"/>
</appSettings>