Consider the following code in a method where an ILogger<>
is injected in the constructor:
using (_logger.BeginScope("Requesting {page} for {identification}", page, identification))
{
if (identification == null)
{
var test = "Test String";
_logger.LogTrace("No identification present {test}. Presenting Index page", test);
return Page();
}
_logger.LogDebug("Identification present: {identification}", identification);
}
where I'd expect some information regarding the scope; although I don't know how it looks like but I assume it's added to the CustomDimensions along the LoggerName
and test
properties.
In my startup class I have this:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<ApplicationInsightsServiceOptions>(Configuration.GetSection("ApplicationInsights"));
services.AddApplicationInsightsTelemetry();
LogManager.Configuration = new NLogLoggingConfiguration(Configuration.GetSection("NLog"));
/// ... the reset
}
My appsettings.json looks like this:
{
"Logging": {
"IncludeScopes": true,
"NLog": {
"IncludeScopes": true
},
"LogLevel": {
"Default": "Trace",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
},
"ApplicationInsights": {
"IncludeScopes": true,
"LogLevel": {
"Default": "Trace"
}
}
},
"NLog": {
"autoReload": true,
"throwConfigExceptions": true,
"internalLogLevel": "trace",
"internalLogFile": "${basedir}/internal-nlog.txt",
"extensions": [
{
"assembly": "Microsoft.ApplicationInsights.NLogTarget"
}
],
"targets": {
"aiTarget": {
"type": "ApplicationInsightsTarget"
},
"logconsole": {
"type": "ColoredConsole"
}
},
"rules": [
{
"logger": "*",
"minLevel": "Trace",
"writeTo": "aiTarget, logconsole"
}
]
}
Is there something that I'm missing...?