SerilogWeb.Classic 5.1.66

dotnet add package SerilogWeb.Classic --version 5.1.66
NuGet\Install-Package SerilogWeb.Classic -Version 5.1.66
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<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
#r "nuget: SerilogWeb.Classic, 5.1.66"
#r directive can be used in F# Interactive and Polyglot Notebooks. 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

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"} )
));
Product Compatible and additional computed target framework versions.
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

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 Downloads Last updated
5.1.66 798,236 4/20/2021
5.0.61 745,378 4/22/2020
5.0.58 2,447 4/21/2020
5.0.56 160,150 2/26/2020
5.0.52 649,030 4/4/2019
5.0.48 295,822 2/28/2019
4.2.42 561,894 5/29/2018
4.2.41 25,377 5/24/2018
4.1.38 17,829 5/22/2018
4.0.30 178,140 3/12/2018
3.0.24 28,269 2/10/2018
3.0.20 504,012 10/11/2017
3.0.19 2,703 10/11/2017
2.1.17 181,654 6/13/2017
2.1.15 26,573 5/17/2017
2.1.13 29,125 4/7/2017
2.0.12 2,094 4/7/2017
2.0.10 174,660 9/23/2016
2.0.9 133,896 2/16/2016
2.0.8 1,927 2/16/2016
2.0.7 1,908 2/16/2016
2.0.6 34,248 9/29/2015
2.0.5 16,325 8/18/2015
2.0.4 13,557 8/14/2015
2.0.3 25,839 7/12/2015
2.0.2 17,048 6/15/2015
2.0.1 2,747 9/23/2016
1.0.1 36,265 4/7/2015