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"
}
]
}
내가 놓친 것이 있습니까 ...?
나는 이것을 시도 할 수 있다고 생각한다.
"targets": {
"aiTarget": {
"type": "ApplicationInsightsTarget",
"contextproperties": [
{
"name": "scopecontext",
"layout": {
"type": "JsonLayout",
"includemdlc": "true"
}
}]
},
"logconsole": {
"type": "ColoredConsole"
}
},
https://github.com/microsoft/ApplicationInsights-dotnet/pull/2103 도 만들었습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다