Overview¶
VC Platform supports two logging libraries out of the box:
-
Serilog (built-in in the platform).
-
MS Azure Application Insights (as separated module).
Note
Starting from version 3.304.0 we are transitioning to Serliog library for leverage more advanced logging capabilities like structured data, storing log events in various formats, data enrichment option, etc. As part of this transition, Azure Application Insights has been moved to a dedicated Virto Commerce module, offering even more flexibility and control over your logging and telemetry.
Basic scenarios¶
Here are basic usage scenarios how to use platform logging.
Configuring logging¶
Logging configuration is provided by the Serilog
section of appsettings.{ENVIRONMENT}.json files, where the {ENVIRONMENT}
placeholder is the environment.
Here is an example of Serilog configuration. In this file we use two sinks (Console and Debug) for writing logs, and also define default severity level for lg.
{
"Serilog": {
"Using": [
"Serilog.Sinks.Console",
"Serilog.Sinks.Debug"
],
"MinimumLevel": {
"Default": "Error",
"Override": {
"Microsoft.AspNetCore": "Information"
}
},
"WriteTo": [
"Console",
"Debug"
]
}
}
In this example:
- The two sinks (Console and Debug) are used to writing logs.
- The log level
Error
is set as default. That means, all logs messages with log levelError
or higher will be logged, all other logs with log level lower thanError
likeInformation
,Trace
,Debug
will be skipped. - The
Microsoft.AspNetCore
category applies to all categories that start withMicrosoft.AspNetCore
. For example, this setting applies to theMicrosoft.AspNetCore.Routing.EndpointMiddleware
category. - The
Microsoft.AspNetCore
category logs at log levelInformation
and higher.
See more configuration examples
Writing log events¶
Log events are written to sinks using the Log
static class, or the methods on an ILogger
:
The same example using ILogging
interface:
References:
Next steps: