![]() |
VOOZH | about |
dotnet add package SerilogWeb.Classic --version 5.1.66
NuGet\Install-Package SerilogWeb.Classic -Version 5.1.66
<PackageReference Include="SerilogWeb.Classic" Version="5.1.66" />
<PackageVersion Include="SerilogWeb.Classic" Version="5.1.66" />Directory.Packages.props
<PackageReference Include="SerilogWeb.Classic" />Project file
paket add SerilogWeb.Classic --version 5.1.66
#r "nuget: SerilogWeb.Classic, 5.1.66"
#:package SerilogWeb.Classic@5.1.66
#addin nuget:?package=SerilogWeb.Classic&version=5.1.66Install as a Cake Addin
#tool nuget:?package=SerilogWeb.Classic&version=5.1.66Install as a Cake Tool
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
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
The following enrichers are available as extension methods from the LoggerConfiguration.Enrich API:
ClaimsIdentity UserHttpRequestClientHostIP containing Request.UserHostAddress (optionally checking for proxy header)HttpRequestClientHostName containing Request.UserHostNameHttpRequestId with a GUID used to identify requests.HttpRequestNumber with an incrementing number per request.HttpRequestRawUrl with the Raw Url of the Request.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)HttpRequestType with the Request Type (GET or POST).HttpRequestUrl with the Url of the Request.HttpRequestUrlReferrer with the UrlReferrer of the Request.HttpRequestUserAgent with the User Agent of the Request.HttpSessionId with the current ASP.NET session id.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>
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 :
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.
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net45 net45 is compatible. net451 net451 was computed. net452 net452 was computed. net46 net46 was computed. net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
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. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 5.1.66 | 2,314,628 | 4/20/2021 |
| 5.0.61 | 1,091,471 | 4/22/2020 |
| 5.0.58 | 38,613 | 4/21/2020 |
| 5.0.56 | 231,054 | 2/26/2020 |
| 5.0.52 | 967,385 | 4/4/2019 |
| 5.0.48 | 592,283 | 2/28/2019 |
| 4.2.42 | 794,682 | 5/29/2018 |
| 4.2.41 | 66,197 | 5/24/2018 |
| 4.1.38 | 56,342 | 5/22/2018 |
| 4.0.30 | 269,606 | 3/12/2018 |
| 3.0.24 | 71,491 | 2/10/2018 |
| 3.0.20 | 589,914 | 10/11/2017 |
| 3.0.19 | 39,748 | 10/11/2017 |
| 2.1.17 | 233,485 | 6/13/2017 |
| 2.1.15 | 71,867 | 5/17/2017 |
| 2.1.13 | 69,737 | 4/7/2017 |
| 2.0.12 | 38,773 | 4/7/2017 |
| 2.0.10 | 229,133 | 9/23/2016 |
| 2.0.1 | 38,952 | 9/23/2016 |