SerilogWeb.Classic 5.1.66

Logs details of System.Web HTTP requests through Serilog.

Install-Package SerilogWeb.Classic -Version 5.1.66
dotnet add package SerilogWeb.Classic --version 5.1.66
<PackageReference Include="SerilogWeb.Classic" Version="5.1.66" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SerilogWeb.Classic --version 5.1.66
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SerilogWeb.Classic, 5.1.66"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install SerilogWeb.Classic as a Cake Addin
#addin nuget:?package=SerilogWeb.Classic&version=5.1.66

// Install SerilogWeb.Classic as a Cake Tool
#tool nuget:?package=SerilogWeb.Classic&version=5.1.66
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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

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 as extension methods from the LoggerConfiguration.Enrich API:

  • WithClaimValue : adds a property contaning the value of a given claim from the current ClaimsIdentity User
  • WithHttpRequestClientHostIP : adds a property HttpRequestClientHostIP containing Request.UserHostAddress (optionally checking for proxy header)
  • WithHttpRequestClientHostName : adds a property HttpRequestClientHostName containing Request.UserHostName
  • WithHttpRequestId : adds a property HttpRequestId with a GUID used to identify requests.
  • WithHttpRequestNumber : adds a property HttpRequestNumber with an incrementing number per request.
  • WithHttpRequestRawUrl : adds a property HttpRequestRawUrl with the Raw Url of the Request.
  • WithHttpRequestTraceId : 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)
  • WithHttpRequestType : adds a property HttpRequestType with the Request Type (GET or POST).
  • WithHttpRequestUrl : adds a property HttpRequestUrl with the Url of the Request.
  • WithHttpRequestUrlReferrer : adds a property HttpRequestUrlReferrer with the UrlReferrer of the Request.
  • WithHttpRequestUserAgent : adds a property HttpRequestUserAgent with the User Agent of the Request.
  • WithHttpSessionId : adds a property HttpSessionId with the current ASP.NET session id.
  • WithUserName : 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.WithHttpRequestId()
    .Enrich.WithUserName()
    .CreateLogger();

To override the username enricher behaviour:

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

Enrichers can also be defined in a configuration file by using Serilog.Settings.AppSettings as follows:

<appSettings>
    <add key="serilog:using:SerilogWeb.Classic" value="SerilogWeb.Classic"/>
    <add key="serilog:enrich:WithClaimValue.claimProperty" value="MyClaimPropertyName"/>
    <add key="serilog:enrich:WithHttpRequestClientHostIP"/>
    <add key="serilog:enrich:WithHttpRequestClientHostName"/>
    <add key="serilog:enrich:WithHttpRequestId"/>
    <add key="serilog:enrich:WithHttpRequestNumber"/>
    <add key="serilog:enrich:WithHttpRequestRawUrl"/>
    <add key="serilog:enrich:WithHttpRequestTraceId"/>
    <add key="serilog:enrich:WithHttpRequestType"/>
    <add key="serilog:enrich:WithHttpRequestUrl"/>
    <add key="serilog:enrich:WithHttpRequestUrlReferrer"/>
    <add key="serilog:enrich:WithHttpRequestUserAgent"/>
    <add key="serilog:enrich:WithHttpSessionId"/>
    <add key="serilog:enrich:WithUserName"/>
</appSettings>

HttpModule

The ApplicationLifecycleModule Http module is automatically hooked up into your ASP.NET application as soon as you install the SerilogWeb.Classic package.

For each HTTP request that hits your application, this module will write log events containing information such as :

  • Url
  • Http Method
  • Response status code
  • Processing time

Regular events are written at Information level, and unhandled exceptions are captured and written at the Error level.

Optionally, form data that is posted to the server can also be captured.

The behavior of the Http module should fit most needs by default, but can be customized for finer control.

Fluent Configuration API

SerilogWeb.Classic v4.1 introduced a new fluent configuration API that is more discoverable and easier to test. The previous configuration mechanisms are still supported, but are considered obsolete and will be removed in a future major version.

All the configuration is done through method calls on SerilogWebClassic.Configure(cfg => cfg.xxx()).

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 LogAtLevel() method:

SerilogWebClassic.Configure(cfg => cfg
  .LogAtLevel(LogEventLevel.Debug)
);

(new in v5.1) If you want even more control, you can pass a callback to .LogAtLevel() and provide a Func<HttpContextBase, TimeSpan, LogEventLevel> like this :

SerilogWebClassic.Configure(cfg => cfg
  .LogAtLevel((context, elapsed) => elapsed.TotalMilliseconds > 3000 ? LogEventLevel.Warning : LogEventLevel.Information)
);

To enable the capture of posted form data:

SerilogWebClassic.Configure(cfg => cfg
  .EnableFormDataLogging()
);
// or
SerilogWebClassic.Configure(cfg => cfg
  .EnableFormDataLogging(forms => forms
    .OnlyOnError()
));
// or
SerilogWebClassic.Configure(cfg => cfg.
  .EnableFormDataLogging(forms => forms
    .OnMatch(ctx => !ctx.Request.Url.PathAndQuery.StartsWith("/__browserLink"))
));

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

SerilogWebClassic.Configure(cfg => cfg
  .EnableFormDataLogging(forms => forms
    .DisablePasswordFiltering()
));

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

SerilogWebClassic.Configure(cfg => cfg
  .Disable()
);

The configuration method calls are chainable, so a full configuration may look like :

SerilogWebClassic.Configure(cfg => cfg
  .UseLogger(myCustomLogger)
  .LogAtLevel(LogEventLevel.Debug)
  .IgnoreRequestsMatching(ctx => !ctx.Request.IsAuthenticated)
  .EnableFormDataLogging(forms => forms
    .AtLevel(LogEventLevel.Debug)
    .OnlyOnError()
    .FilterKeywords(new[] {"password", "authToken"} )
));

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

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 as extension methods from the LoggerConfiguration.Enrich API:

  • WithClaimValue : adds a property contaning the value of a given claim from the current ClaimsIdentity User
  • WithHttpRequestClientHostIP : adds a property HttpRequestClientHostIP containing Request.UserHostAddress (optionally checking for proxy header)
  • WithHttpRequestClientHostName : adds a property HttpRequestClientHostName containing Request.UserHostName
  • WithHttpRequestId : adds a property HttpRequestId with a GUID used to identify requests.
  • WithHttpRequestNumber : adds a property HttpRequestNumber with an incrementing number per request.
  • WithHttpRequestRawUrl : adds a property HttpRequestRawUrl with the Raw Url of the Request.
  • WithHttpRequestTraceId : 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)
  • WithHttpRequestType : adds a property HttpRequestType with the Request Type (GET or POST).
  • WithHttpRequestUrl : adds a property HttpRequestUrl with the Url of the Request.
  • WithHttpRequestUrlReferrer : adds a property HttpRequestUrlReferrer with the UrlReferrer of the Request.
  • WithHttpRequestUserAgent : adds a property HttpRequestUserAgent with the User Agent of the Request.
  • WithHttpSessionId : adds a property HttpSessionId with the current ASP.NET session id.
  • WithUserName : 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.WithHttpRequestId()
    .Enrich.WithUserName()
    .CreateLogger();

To override the username enricher behaviour:

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

Enrichers can also be defined in a configuration file by using Serilog.Settings.AppSettings as follows:

<appSettings>
    <add key="serilog:using:SerilogWeb.Classic" value="SerilogWeb.Classic"/>
    <add key="serilog:enrich:WithClaimValue.claimProperty" value="MyClaimPropertyName"/>
    <add key="serilog:enrich:WithHttpRequestClientHostIP"/>
    <add key="serilog:enrich:WithHttpRequestClientHostName"/>
    <add key="serilog:enrich:WithHttpRequestId"/>
    <add key="serilog:enrich:WithHttpRequestNumber"/>
    <add key="serilog:enrich:WithHttpRequestRawUrl"/>
    <add key="serilog:enrich:WithHttpRequestTraceId"/>
    <add key="serilog:enrich:WithHttpRequestType"/>
    <add key="serilog:enrich:WithHttpRequestUrl"/>
    <add key="serilog:enrich:WithHttpRequestUrlReferrer"/>
    <add key="serilog:enrich:WithHttpRequestUserAgent"/>
    <add key="serilog:enrich:WithHttpSessionId"/>
    <add key="serilog:enrich:WithUserName"/>
</appSettings>

HttpModule

The ApplicationLifecycleModule Http module is automatically hooked up into your ASP.NET application as soon as you install the SerilogWeb.Classic package.

For each HTTP request that hits your application, this module will write log events containing information such as :

  • Url
  • Http Method
  • Response status code
  • Processing time

Regular events are written at Information level, and unhandled exceptions are captured and written at the Error level.

Optionally, form data that is posted to the server can also be captured.

The behavior of the Http module should fit most needs by default, but can be customized for finer control.

Fluent Configuration API

SerilogWeb.Classic v4.1 introduced a new fluent configuration API that is more discoverable and easier to test. The previous configuration mechanisms are still supported, but are considered obsolete and will be removed in a future major version.

All the configuration is done through method calls on SerilogWebClassic.Configure(cfg => cfg.xxx()).

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 LogAtLevel() method:

SerilogWebClassic.Configure(cfg => cfg
  .LogAtLevel(LogEventLevel.Debug)
);

(new in v5.1) If you want even more control, you can pass a callback to .LogAtLevel() and provide a Func<HttpContextBase, TimeSpan, LogEventLevel> like this :

SerilogWebClassic.Configure(cfg => cfg
  .LogAtLevel((context, elapsed) => elapsed.TotalMilliseconds > 3000 ? LogEventLevel.Warning : LogEventLevel.Information)
);

To enable the capture of posted form data:

SerilogWebClassic.Configure(cfg => cfg
  .EnableFormDataLogging()
);
// or
SerilogWebClassic.Configure(cfg => cfg
  .EnableFormDataLogging(forms => forms
    .OnlyOnError()
));
// or
SerilogWebClassic.Configure(cfg => cfg.
  .EnableFormDataLogging(forms => forms
    .OnMatch(ctx => !ctx.Request.Url.PathAndQuery.StartsWith("/__browserLink"))
));

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

SerilogWebClassic.Configure(cfg => cfg
  .EnableFormDataLogging(forms => forms
    .DisablePasswordFiltering()
));

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

SerilogWebClassic.Configure(cfg => cfg
  .Disable()
);

The configuration method calls are chainable, so a full configuration may look like :

SerilogWebClassic.Configure(cfg => cfg
  .UseLogger(myCustomLogger)
  .LogAtLevel(LogEventLevel.Debug)
  .IgnoreRequestsMatching(ctx => !ctx.Request.IsAuthenticated)
  .EnableFormDataLogging(forms => forms
    .AtLevel(LogEventLevel.Debug)
    .OnlyOnError()
    .FilterKeywords(new[] {"password", "authToken"} )
));

NuGet packages (6)

Showing the top 5 NuGet packages that depend on SerilogWeb.Classic:

Package Downloads
SerilogWeb.Classic.WebApi
Adds WebAPI exception logging to SerilogWeb.Classic
SerilogWeb.Classic.Mvc
Adds ASP.NET MVC enrichers to SerilogWeb.Classic
Serilog.Extras.Web
Obsolete. Please install SerilogWeb.Classic.
Serilog.Sinks.Buffered.Web
Offers buffered logging to Serilog to only write to the log upon a specific log level. The web version automatically buffers based on the HTTP Request Id.
Creuna.Diagnostics.Web.Episerver
A starter kit to quickly add Serilog/AppInisghts/Operations based diagnostics to an episerver application.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
5.1.66 5,241 4/20/2021
5.0.61 197,646 4/22/2020
5.0.58 823 4/21/2020
5.0.56 53,764 2/26/2020
5.0.52 355,561 4/4/2019
5.0.48 146,930 2/28/2019
4.2.42 321,187 5/29/2018
4.2.41 16,489 5/24/2018
4.1.38 9,385 5/22/2018
4.0.30 87,650 3/12/2018
3.0.24 19,460 2/10/2018
3.0.20 318,350 10/11/2017
3.0.19 1,101 10/11/2017
2.1.17 122,868 6/13/2017
2.1.15 18,787 5/17/2017
2.1.13 20,945 4/7/2017
2.0.12 797 4/7/2017
2.0.10 141,619 9/23/2016
2.0.9 91,165 2/16/2016
2.0.8 647 2/16/2016
2.0.7 662 2/16/2016
2.0.6 22,521 9/29/2015
2.0.5 14,863 8/18/2015
2.0.4 3,989 8/14/2015
2.0.3 22,706 7/12/2015
2.0.2 13,073 6/15/2015
2.0.1 1,061 9/23/2016
1.0.1 21,399 4/7/2015