【发布时间】:2020-10-30 12:08:17
【问题描述】:
在构造函数中注入ILogger<> 的方法中考虑以下代码:
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);
}
我希望获得有关范围的一些信息;虽然我不知道它是什么样子,但我认为它是沿着 LoggerName 和 test 属性添加到 CustomDimensions 中的。
在我的创业课程中,我有这个:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<ApplicationInsightsServiceOptions>(Configuration.GetSection("ApplicationInsights"));
services.AddApplicationInsightsTelemetry();
LogManager.Configuration = new NLogLoggingConfiguration(Configuration.GetSection("NLog"));
/// ... the reset
}
我的 appsettings.json 看起来像这样:
{
"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"
}
]
}
我有什么遗漏的吗...?
【问题讨论】:
标签: asp.net-core azure-application-insights nlog