Giter VIP home page Giter VIP logo

classic's Introduction

SerilogWeb.Classic Build status NuGet

Web request logging and enrichment for classic ASP.NET applications (System.Web).

Package - SerilogWeb.Classic | Platforms - .NET 4.5

This package replaces the Serilog.Extras.Web package previously included in the Serilog project.

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

When you work with an ASP.NET web application, this package adds

  • additional enrichers
  • an HttpModule to enhance the logging output.

When working with ASP.NET MVC (not Core) or ASP.NET Web API, you may also want to have a look at SerilogWeb.Classic.Mvc and SerilogWeb.Classic.WebAPI

Enrichers

The following enrichers are available in the SerilogWeb.Classic.Enrichers namespace:

  • ClaimValueEnricher : adds a property contaning the value of a given claim from the current ClaimsIdentity User
  • HttpRequestClientHostIPEnricher : adds a property HttpRequestClientHostIP containing Request.UserHostAddress (optionally checking for proxy header)
  • HttpRequestClientHostNameEnricher : adds a property HttpRequestClientHostName containing Request.UserHostName
  • HttpRequestIdEnricher : adds a property HttpRequestId with a GUID used to identify requests.
  • HttpRequestNumberEnricher : adds a property HttpRequestNumber with an incrementing number per request.
  • HttpRequestRawUrlEnricher : adds a property HttpRequestRawUrl with the Raw Url of the Request.
  • HttpRequestTraceIdEnricher : adds a property HttpRequestTraceId with a GUID matching the RequestTraceIdentifier assigned by IIS and used throughout ASP.NET/ETW. (IIS ETW tracing must be enabled for this to work)
  • HttpRequestTypeEnricher : adds a property HttpRequestType with the Request Type (GET or POST).
  • HttpRequestUrlEnricher : adds a property HttpRequestUrl with the Url of the Request.
  • HttpRequestUrlReferrerEnricher : adds a property HttpRequestUrlReferrer with the UrlReferrer of the Request.
  • HttpRequestUserAgentEnricher : adds a property HttpRequestUserAgent with the User Agent of the Request.
  • HttpSessionIdEnricher : adds a property HttpSessionId with the current ASP.NET session id.
  • UserNameEnricher : adds a property UserName with the current username or, when anonymous, a defined value. By default this is set to (anonymous).
var log = new LoggerConfiguration()
    .WriteTo.Console()
    .Enrich.With<HttpRequestIdEnricher>()
    .Enrich.With<UserNameEnricher>()
    .CreateLogger();

To override the username enricher behaviour:

var log = new LoggerConfiguration()
    .WriteTo.ColoredConsole()
    .Enrich.With(new UserNameEnricher("not known yet", System.Environment.UserName))
    .CreateLogger();

HttpModule

The ApplicationLifecycleModule will automatically be enabled and will write information events about the current method and url that is being accessed. Optionally you also store any form data that is posted to the server. When an unhandled exception occurs, the module will capture it and log it as an error event.

Configuration

No configuration is necessary, but most of the built-in behavior can be changed using properties on the ApplicationLifecycleModule class.

By default, all requests will be logged at the Information level. To change this (i.e. to generate less events under normal conditions) use the RequestLoggingLevel property:

ApplicationLifecycleModule.RequestLoggingLevel = LogEventLevel.Debug;

To enable the posting of form data:

ApplicationLifecycleModule.LogPostedFormData = LogPostedFormDataOption.Always;
// or
ApplicationLifecycleModule.LogPostedFormData = LogPostedFormDataOption.OnlyOnError;

Any fields containing the phrase 'password' will be filtered from the logged form data. This can be disabled with:

ApplicationLifecycleModule.FilterPasswordsInFormData = false;

If you want to disable the logging completely, use the following statement:

ApplicationLifecycleModule.IsEnabled = false;

classic's People

Contributors

advapiit avatar csjci avatar daveaglick avatar james-kelly-fcnsw avatar joergbattermann avatar khellang avatar mattgwagner avatar merbla avatar mivano avatar nblumhardt avatar paulblamire avatar phil-scott-78 avatar raj-mahich avatar richardlawley avatar ryanande avatar simoncropp avatar tsimbalar avatar

Watchers

 avatar  avatar  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.