Skip to content

Commit 8e6e57d

Browse files
committed
Updates
1 parent 29d5ef2 commit 8e6e57d

File tree

1 file changed

+134
-3
lines changed

1 file changed

+134
-3
lines changed

aspnetcore/fundamentals/logging/index.md

Lines changed: 134 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
title: Logging in .NET and ASP.NET Core
3+
ai-usage: ai-assisted
34
author: tdykstra
45
description: Learn how to use the ASP.NET Core logging framework provided by the Microsoft.Extensions.Logging NuGet package.
56
monikerRange: '>= aspnetcore-3.1'
@@ -484,7 +485,7 @@ For more information, see [Azure Apps: Override app configuration using the Azur
484485

485486
When an <xref:Microsoft.Extensions.Logging.ILogger> object is created, a *category* is specified. The category is included with each log message created by that instance of the logger. The category string is arbitrary, but the convention is to use the fully qualified class name. The ASP.NET Core web apps use [`ILogger<T>`](xref:Microsoft.Extensions.Logging.ILogger) to create a logger instance that uses the fully qualified type name of `T` as the category.
486487

487-
Log messages with a category name that begins with "Microsoft" are from .NET. Typically, log messages that begin with the app's assembly name are from the app. Packages outside of .NET usually have a category based on the assembly name from the package.
488+
Log messages with a category name that begins with "Microsoft" are from .NET. Typically, log messages that begin with the app's assembly name are from the app. Packages outside of .NET usually have a category based on the assembly name from the package. For a list of common log categories, see the [Common log categories](#common-log-categories) section.
488489

489490
In a Razor component of a Blazor app, where the type `T` is `Counter` for a privacy page rendered by a `Counter` component (`Pages/Counter.razor`):
490491

@@ -867,7 +868,7 @@ For information on `stdout` and debug logging with the ASP.NET Core Module, see
867868

868869
### `Console`
869870

870-
The `Console` provider logs output to the console. For more information on viewing `Console` logs in development, see [Logging output from dotnet run and Visual Studio](#logging-output-from-dotnet-run-and-visual-studio).
871+
The `Console` provider logs output to the console. For more information on viewing `Console` logs in development, see the [Logging output](#logging-output) section.
871872

872873
### `Debug`
873874

@@ -1089,6 +1090,8 @@ builder.Logging.AddEventLog(eventLogSettings =>
10891090
});
10901091
```
10911092

1093+
When the app calls the <xref:Microsoft.Extensions.Logging.EventLoggerFactoryExtensions.AddEventLog%2A> overload with <xref:Microsoft.Extensions.Logging.EventLog.EventLogSettings>, a new instance of <xref:Microsoft.Extensions.Logging.EventLog.EventLogLoggerProvider> is created with the provided settings. If there's already an <xref:Microsoft.Extensions.Logging.EventLog.EventLogLoggerProvider> instance registered, which is the case if the app doesn't call <xref:Microsoft.Extensions.Logging.LoggingBuilderExtensions.ClearProviders%2A> to remove all the <xref:Microsoft.Extensions.Logging.ILoggerProvider> instances, the new settings don't replace the existing ones. If you want to ensure that the <xref:Microsoft.Extensions.Logging.EventLog.EventLogSettings> are used, call <xref:Microsoft.Extensions.Logging.LoggingBuilderExtensions.ClearProviders%2A> before calling <xref:Microsoft.Extensions.Logging.EventLoggerFactoryExtensions.AddEventLog%2A>.
1094+
10921095
### Azure App Service
10931096

10941097
The [`Microsoft.Extensions.Logging.AzureAppServices` provider NuGet package](https://www.nuget.org/packages/Microsoft.Extensions.Logging.AzureAppServices) writes logs to text files in an Azure App Service app's file system and to [blob storage](/azure/storage/blobs/storage-quickstart-blobs-dotnet#what-is-blob-storage) in an Azure Storage account. The provider only logs when the project runs in the Azure environment.
@@ -1271,7 +1274,7 @@ In the preceding example:
12711274
* All categories starting with `"Microsoft"`.
12721275
* Log level <xref:Microsoft.Extensions.Logging.LogLevel.Trace> and higher.
12731276

1274-
:::moniker range=">= aspnetcore-5.0
1277+
:::moniker range=">= aspnetcore-5.0"
12751278

12761279
## Specify the trace context for logging scopes
12771280

@@ -1287,6 +1290,8 @@ The logging libraries implicitly create a scope object with <xref:Microsoft.Exte
12871290
* `Baggage`
12881291
* `Tags`
12891292

1293+
`SpanId`, `TraceId`, `ParentId` are enabled by default.
1294+
12901295
In the following example, only the `SpanId` and `TraceId` are specified:
12911296

12921297
```csharp
@@ -1325,6 +1330,8 @@ The logging libraries implicitly create a scope object with <xref:Microsoft.Exte
13251330
* `TraceId`
13261331
* `ParentId`
13271332

1333+
`SpanId`, `TraceId`, `ParentId` are enabled by default.
1334+
13281335
In the following example, only the `SpanId` and `TraceId` are specified:
13291336

13301337
```csharp
@@ -1341,6 +1348,8 @@ var loggerFactory = LoggerFactory.Create(logging =>
13411348
});
13421349
```
13431350

1351+
:::moniker-end
1352+
13441353
:::moniker range=">= aspnetcore-5.0"
13451354

13461355
If the [W3C Trace Context specification](https://www.w3.org/TR/trace-context/) `traceparent` http request header is set:
@@ -1429,6 +1438,128 @@ The preceding code is a <xref:System.Func%602> that runs the first time the DI c
14291438

14301439
File a logging bug report in the [`dotnet/runtime` GitHub repository issues](https://github.com/dotnet/runtime/issues).
14311440

1441+
## Common log categories
1442+
1443+
<!-- Dan, I merely tossed this in from Rick's issue with minor editing ...
1444+
1445+
https://github.com/dotnet/AspNetCore.Docs/issues/33187
1446+
1447+
I didn't want to spend time on it until I heard back from you
1448+
if we're going to place this section at all or have feedback
1449+
from you on how you want it covered if you'd prefer an
1450+
alternative format and/or the entries Rick drafted. -->
1451+
1452+
This section describes common log categories seen in ASP.NET Core app logs. The following isn't a comprehensive list.
1453+
1454+
`Microsoft.AspNetCore`: Logs from the ASP.NET Core framework components, such as hosting, routing, and middleware.
1455+
1456+
Authentication
1457+
1458+
* `Microsoft.AspNetCore.Authentication`: Logs from the authentication middleware and services, including authentication scheme handling.
1459+
* `Microsoft.AspNetCore.Authentication.Cookies`: Logs specific to cookie-based authentication.
1460+
* `Microsoft.AspNetCore.Authentication.JwtBearer`: Logs related to JWT Bearer token authentication.
1461+
* `Microsoft.AspNetCore.Authentication.OpenIdConnect`: Logs concerning OpenID Connect authentication processes.
1462+
* `Microsoft.AspNetCore.Authentication.OAuth`: Logs related to OAuth authentication and authorization flows.
1463+
1464+
Authorization
1465+
1466+
* `Microsoft.AspNetCore.Authorization`: Logs related to authorization operations, including policy evaluation and decision making.
1467+
* `Microsoft.AspNetCore.Authorization.DefaultAuthorizationService`: Logs about the default.
1468+
1469+
Configuration
1470+
1471+
* `Microsoft.Extensions.Configuration.Json`: Logs from classes that obtain configuration data from JSON files.
1472+
* `Microsoft.Extensions.Configuration.UserSecrets`: Logs related to loading user secrets configuration data.
1473+
1474+
CORS
1475+
1476+
* `Microsoft.AspNetCore.Cors`: Logs related to Cross-Origin Resource Sharing (CORS) middleware and policy evaluation.
1477+
* `Microsoft.AspNetCore.Cors.Infrastructure`: Logs concerning CORS policy configuration and enforcement.
1478+
1479+
Data Protection:
1480+
1481+
* `Microsoft.AspNetCore.DataProtection`: Logs from the data protection system, including key management, encryption operations, and which keys were considered, found, and used.
1482+
* `Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager`: Logs specific to the XML key manager, including key storage and retrieval.
1483+
1484+
Diagnostics
1485+
1486+
* `Microsoft.AspNetCore.Diagnostics`: Logs about diagnostics and error handling middleware, including exception handling and status code pages.
1487+
* `Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware`: Logs specific to developer exception page middleware processing.
1488+
* `Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware`: Logs related to exception handling and error response generation.
1489+
* `Microsoft.AspNetCore.Diagnostics.StatusCodePageMiddleware`: Logs related to status code page middleware and response handling.
1490+
1491+
Host Filtering
1492+
1493+
* `Microsoft.AspNetCore.HostFiltering`: Hosts allowed and denied by the host filtering middleware.
1494+
* `Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware`: Logs related to the host filtering middleware, including allowed and denied hosts.
1495+
* `Microsoft.AspNetCore.HostFiltering.HostFilteringOptions`: Logs concerning options for the HostFiltering middleware.
1496+
1497+
Hosting
1498+
1499+
* `Microsoft.AspNetCore.Hosting.Lifetime`: Logs related to the lifecycle of the web host, including starting and stopping events.
1500+
* `Microsoft.AspNetCore.Hosting.Diagnostics`: Logs diagnostics information, such as application startup and shutdown.
1501+
* `Microsoft.AspNetCore.Hosting.RequestDelegate`: Logs related to the handling of HTTP requests by the application pipeline.
1502+
* `Microsoft.AspNetCore.Hosting.Internal.WebHost`: Internal logs from the web host, useful for debugging host-related issues.
1503+
* `Microsoft.AspNetCore.Hosting.Internal.HostedServiceExecutor`: Logs concerning the execution of hosted services by the web host.
1504+
1505+
HTTP
1506+
1507+
* `Microsoft.AspNetCore.Http.ConnectionLogging`: Related to HTTP connections, including connection establishment and termination.
1508+
* `Microsoft.AspNetCore.Http.DefaultHttpContext`: Logs related to the creation and usage of HttpContext instances.
1509+
* `Microsoft.AspNetCore.Http.Endpoints.EndpointMiddleware`: Logs about endpoint routing and middleware execution.
1510+
* `Microsoft.AspNetCore.Http.Response`: Logs related to HTTP response processing.
1511+
1512+
HTTPS
1513+
1514+
* `Microsoft.AspNetCore.HttpsPolicy`: Logs from HTTPS redirection middleware, policy enforcement and and HTTP Strict-Transport-Security (HSTS).
1515+
* `Microsoft.AspNetCore.HttpsPolicy.HstsMiddleware`: Logs specific to HTTP Strict-Transport-Security (HSTS) middleware processing.
1516+
* `Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware`: Logs related to HTTPS redirection middleware execution.
1517+
* `Microsoft.AspNetCore.HttpsPolicy.HstsOptions`: Logs concerning HSTS policy configuration and enforcement.
1518+
1519+
Identity
1520+
1521+
* `Microsoft.AspNetCore.Identity`: Logs from the ASP.NET Core Identity framework, including user management and identity operations.
1522+
* `Microsoft.AspNetCore.Identity.RoleManager`: Logs related to role management operations.
1523+
* `Microsoft.AspNetCore.Identity.UserManager`: Logs concerning user management activities and lifecycle events.
1524+
1525+
Kestrel
1526+
1527+
* `Microsoft.AspNetCore.Server.Kestrel`: Logs from the Kestrel web server, covering connection handling and request processing.
1528+
* `Microsoft.AspNetCore.Server.Kestrel.Core`: Logs related to core Kestrel operations, such as configuration and resource management.
1529+
* `Microsoft.AspNetCore.Server.Kestrel.Transport`: Logs specific to network transport layers used by Kestrel.
1530+
1531+
Logging
1532+
1533+
* `Microsoft.Extensions.Logging`: Logs from the logging extensions API.
1534+
* `Microsoft.Extensions.Logging.Console`: Logs specific to the Console logger.
1535+
1536+
MVC
1537+
1538+
* `Microsoft.AspNetCore.Mvc`: General logs from MVC framework components, including controller and action execution.
1539+
* `Microsoft.AspNetCore.Mvc.Infrastructure`: Logs related to the infrastructure and support services for MVC, such as model binding and action filters.
1540+
* `Microsoft.AspNetCore.Mvc.ModelBinding`: Logs concerning model binding operations and data validation.
1541+
* `Microsoft.AspNetCore.Mvc.Filters`: Logs about the execution of action filters and filter pipelines.
1542+
* `Microsoft.AspNetCore.Mvc.Razor`: Logs specific to Razor view rendering and compilation.
1543+
* `Microsoft.AspNetCore.Mvc.ViewFeatures`: Logs concerning view rendering and related features like view components and tag helpers.
1544+
1545+
Routing
1546+
1547+
* `Microsoft.AspNetCore.Routing.EndpointMiddleware`: Logs related to the routing of HTTP requests to endpoints.
1548+
* `Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware`: Logs about the endpoint routing middleware handling requests.
1549+
* `Microsoft.AspNetCore.Routing.Matching.DataSourceDependentMatcher`: Logs concerning route matching and selection of endpoints.
1550+
* `Microsoft.AspNetCore.Routing.Matching.DfaMatcher`: Logs specific to the DFA (Deterministic Finite Automaton) routing matcher.
1551+
1552+
SignalR
1553+
1554+
* `Microsoft.AspNetCore.SignalR`: Logs from the SignalR framework, including hub connections and message handling.
1555+
* `Microsoft.AspNetCore.SignalR.Hub`: Logs specific to hub invocation and message dispatching.
1556+
* `Microsoft.AspNetCore.SignalR.Transports`: Logs related to transport mechanisms used by SignalR.
1557+
1558+
Static files
1559+
1560+
* `Microsoft.AspNetCore.StaticFiles`: Logs from the static files middleware, including file serving and cache operations.
1561+
* `Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware`: Logs related to static file middleware execution and file response handling.
1562+
14321563
## Additional resources
14331564

14341565
* <xref:blazor/fundamentals/logging>

0 commit comments

Comments
 (0)