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
**For .NETCore1.0or1.1**, inyour `Startup` class's `Configure()` method, remove the existing logger configuration entries and call `AddSerilog()` on the provided `loggerFactory`.
55
55
56
56
```
57
-
publicvoidConfigure(IApplicationBuilderapp,
58
-
IHostingEnvironmentenv,
59
-
ILoggerFactoryloggerfactory,
60
-
IApplicationLifetimeappLifetime)
61
-
{
62
-
loggerfactory.AddSerilog();
63
-
64
-
// Ensure any buffered events are sent at shutdown
### Including the log category in text-format sink output
84
+
All_Microsoft.Extensions.Logging.ILogger_implementationsarecreatedwithaspecified [_logcategory_](https://learn.microsoft.com/en-us/dotnet/core/extensions/logging?tabs=command-line#log-category) string, which is then attached as structured data to each log message created by that `ILogger` instance. Typically, the log category is the fully-qualified name of the class generating the log messages. This convention is implemented by the [`ILogger<TCategoryName>`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.ilogger-1) interface, which is commonly used as an injected dependency in frameworks that use _Microsoft.Extensions.Logging_.
85
+
86
+
_Serilog.Extensions.Logging_capturesthe `ILogger`'s log category, but it'snotincludedinthedefaultoutputtemplatesfortext-basedsinks, suchas [Console](https://github.com/serilog/serilog-sinks-console), [File](https://github.com/serilog/serilog-sinks-file) and [Debug](https://github.com/serilog/serilog-sinks-debug).
_logger.LogInformation("Completed in {DurationMs}ms...", 30);
96
110
}
@@ -102,8 +116,9 @@ using (_logger.BeginScope("Transaction")) {
102
116
Ifyousimplywanttoadda"bag"ofadditionalpropertiestoyourlogevents, however, thisextensionmethodapproachcanbeoverlyverbose. Forexample, toadd `TransactionId` and `ResponseJson` propertiestoyourlogevents, youwouldhavetodosomethinglikethefollowing:
103
117
104
118
```csharp
105
-
// WRONG! Prefer the dictionary approach below instead
106
-
using (_logger.BeginScope("TransactionId: {TransactionId}, ResponseJson: {ResponseJson}", 12345, jsonString)) {
119
+
// WRONG! Prefer the dictionary or value tuple approach below instead
120
+
using (_logger.BeginScope("TransactionId: {TransactionId}, ResponseJson: {ResponseJson}", 12345, jsonString))
121
+
{
107
122
_logger.LogInformation("Completed in {DurationMs}ms...", 30);
108
123
}
109
124
// Example JSON output:
@@ -125,11 +140,13 @@ Moreover, the template string within `BeginScope` is rather arbitrary when all y
0 commit comments