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
The following enrichers are available in the SerilogWeb.Classic.WebApi.Enrichers namespace:
- WebApiActionNameEnricher : adds a property
WebApiActioncontaining the name of the Action being executed in the Web API Controller - WebApiControllerNameEnricher : adds a property
WebApiControllercontaining the name of the Controller in which a Web API Action has executed - WebApiRouteDataEnricher : adds a property
WebApiRouteDatacontaining the dictionary of the RouteData - WebApiRouteTemplateEnricher : adds a property
WebApiRouteTemplatecontaining the route template selected by Web API routing
Usage :
var log = new LoggerConfiguration() .WriteTo.Console() .Enrich.With<WebApiRouteTemplateEnricher>() .Enrich.With<WebApiActionNameEnricher>() .CreateLogger();To override the property name of the added property:
var log = new LoggerConfiguration() .WriteTo.Console() .Enrich.With(new WebApiRouteTemplateEnricher("RouteTemplate") .CreateLogger();