You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/fundamentals/logging/index.md
+134-3Lines changed: 134 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,6 @@
1
1
---
2
2
title: Logging in .NET and ASP.NET Core
3
+
ai-usage: ai-assisted
3
4
author: tdykstra
4
5
description: Learn how to use the ASP.NET Core logging framework provided by the Microsoft.Extensions.Logging NuGet package.
5
6
monikerRange: '>= aspnetcore-3.1'
@@ -484,7 +485,7 @@ For more information, see [Azure Apps: Override app configuration using the Azur
484
485
485
486
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.
486
487
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.
488
489
489
490
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`):
490
491
@@ -867,7 +868,7 @@ For information on `stdout` and debug logging with the ASP.NET Core Module, see
867
868
868
869
### `Console`
869
870
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.
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
+
1092
1095
### Azure App Service
1093
1096
1094
1097
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:
1271
1274
* All categories starting with `"Microsoft"`.
1272
1275
* Log level <xref:Microsoft.Extensions.Logging.LogLevel.Trace> and higher.
1273
1276
1274
-
:::moniker range=">= aspnetcore-5.0
1277
+
:::moniker range=">= aspnetcore-5.0"
1275
1278
1276
1279
## Specify the trace context for logging scopes
1277
1280
@@ -1287,6 +1290,8 @@ The logging libraries implicitly create a scope object with <xref:Microsoft.Exte
1287
1290
*`Baggage`
1288
1291
*`Tags`
1289
1292
1293
+
`SpanId`, `TraceId`, `ParentId` are enabled by default.
1294
+
1290
1295
In the following example, only the `SpanId` and `TraceId` are specified:
1291
1296
1292
1297
```csharp
@@ -1325,6 +1330,8 @@ The logging libraries implicitly create a scope object with <xref:Microsoft.Exte
1325
1330
*`TraceId`
1326
1331
*`ParentId`
1327
1332
1333
+
`SpanId`, `TraceId`, `ParentId` are enabled by default.
1334
+
1328
1335
In the following example, only the `SpanId` and `TraceId` are specified:
1329
1336
1330
1337
```csharp
@@ -1341,6 +1348,8 @@ var loggerFactory = LoggerFactory.Create(logging =>
1341
1348
});
1342
1349
```
1343
1350
1351
+
:::moniker-end
1352
+
1344
1353
:::moniker range=">= aspnetcore-5.0"
1345
1354
1346
1355
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
1429
1438
1430
1439
File a logging bug report in the [`dotnet/runtime` GitHub repository issues](https://github.com/dotnet/runtime/issues).
1431
1440
1441
+
## Common log categories
1442
+
1443
+
<!-- Dan, I merely tossed this in from Rick's issue with minor editing ...
*`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.
0 commit comments