Coder Social home page Coder Social logo

classic-webapi's Introduction

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>

classic-webapi's People

Contributors

tsimbalar avatar nblumhardt avatar gareth-james avatar dgarciarubio avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.