Ilogger(1) 이해 - Cole App
ILogger를 하고 싶다.이번에는 콘스토어 앱ILogger의 기본 기능과 다음에ASPNetCore 포인트를 사용한 것을 이해하고자 두 차례에 걸쳐 쓸 계획이다.사용된 버전
이번에 사용한 것은dotnet5다.사용하는 라이브러리의 버전은 다음과 같습니다.
ILoggerSpike.csproj<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.17.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
</ItemGroup>
</Project>
간단한 Ilogger 사용
콘솔에서 사용하려면ILogger 사용할 수 있습니다LoggerFactory.콘솔에 대한 Logging을 실현하려면 Microsoft.Extensions.Logging.Console, ILoggingBuilder에 대해서는 추가AddConsole() 또는 AddJsonConsole()도 가능하다.이번에는 제이슨 출력 포맷을 쓰고 싶어 사용했다AddJsonConsole().이것은dotnet5에서 사용하기 시작한 인터페이스이기 때문에 이번에dotnet5를 스매시에 사용합니다.options의 설정 내용은 뒤에 설명됩니다.이러한 로그 형식에 대한 지원
참조할 수 있습니다Console log formatting.using var loggerFactory = LoggerFactory.Create(builder =>
{
// builder.AddConsole(); // Plain
builder.AddJsonConsole(
options => options.IncludeScopes = true // Enable Scope
); // from net 5; otherwise you need to implement it.
ILogger logger = loggerFactory.CreateLogger<Program>();
logger.LogInformation(AppLogEvents.Details, "Start Program with {Id} at {RunTime}", 1, DateTime.Now);
로그 템플릿 사용
아래 코드를 보면 왜 최신 형식으로 Substite를 쓰지 않는지 생각할 수 있을 거예요.$"{something} is substitution"의 형식.이 형식으로 쓰면 기록을 출력할 때Id = 1,Runtime = DateTime.Now로 개별 항목으로 식별할 수 있다는 이유가 있다.이것은 정식으로 운용할 때 로그를 검색할 때 매우 편리할 것이다.logger.LogInformation(AppLogEvents.Details, "Start Program with {Id} at {RunTime}", 1, DateTime.Now);
또한 AppLogEvents.Details는 맞춤형 클래스로 간단하게 정의int했다.이는 초기 매개 변수가 이벤트 로그 이벤트의 종류를 구별하기 위한 항목이었기 때문입니다.다음 실행 결과에서 "Id":1,"RunTime":"06/26/2021 23:26:07"라는 단독 항목을 확인할 수 있습니다.
log{"EventId":3000,"LogLevel":"Information","Category":"ILoggerSpike.Program","Message":"Start Program with 1 at 06/26/2021 23:26:07","State":{"Message":"Start Program with 1 at 06/26/2021 23:26:07","Id":1,"RunTime":"06/26/2021 23:26:07","{OriginalFormat}":"Start Program with {Id} at {RunTime}"},"Scopes":["simple","start console"]}
Scope 사용
그러면 로그를 유효하게 할 때, 때때로 역할 영역을 정의하려고 합니다.특정한 방법은 호출 창고의 일부분으로 호출되는 것입니까?의 경우다음과 같이 기술하다.이 로그를 출력해 보세요.using (logger.BeginScope("DI enabled"))
using (logger.BeginScope("start console"))
{
logger.LogInformation(AppLogEvents.Details, "Start Program with {Id} at {RunTime}", 1, DateTime.Now);
try
{
throw new CustomException("tsushi's exception thrown.");
}
catch (CustomException e)
{
logger.LogError(AppLogEvents.Error, e, "Check the host.json configuration.");
}
}
logger.LogInformation(AppLogEvents.Details, "out of scope");
"Scopes":["simple","start console"]가 매 도량에 추가됩니다.
log{"EventId":3000,"LogLevel":"Information","Category":"ILoggerSpike.Program","Message":"Start Program with 1 at 06/26/2021 23:26:07","State":{"Message":"Start Program with 1 at 06/26/2021 23:26:07","Id":1,"RunTime":"06/26/2021 23:26:07","{OriginalFormat}":"Start Program with {Id} at {RunTime}"},"Scopes":["simple","start console"]}
{"EventId":3001,"LogLevel":"Error","Category":"ILoggerSpike.Program","Message":"Check the host.json configuration.","Exception":"ILoggerSpike.CustomException: tsushi\u0027s exception thrown. at ILoggerSpike.Program.SimpleConsole() in C:\\Users\\tsushi\\source\\repos\\ILoggerSpike\\ILoggerSpike\\Program.cs:line 81","State":{"Message":"Check the host.json configuration.","{OriginalFormat}":"Check the host.json configuration."},"Scopes":["simple","start console"]}
{"EventId":3000,"LogLevel":"Information","Category":"ILoggerSpike.Program","Message":"out of scope","State":{"Message":"out of scope","{OriginalFormat}":"out of scope"},"Scopes":[]}
Application Insight 사용 ILogger는 인터페이스이며 하나의 실례에서 여러 개의 로그인 공급자에게 출력할 수 있다.이번에는 콘솔을 사용해 애플 인사이트의 공급업체를 사용해 봤다.Microsoft.Extensions.Logging.ApplicationInsights를 NuGet 패키지로 가져오고 ILoggingBuilder에서 다음과 같은 설정을 할 수 있습니다.그나저나 Microsoft.Extensions.Logging.ApplicationInsights 최신2.x도dotnet 5를 위한5.x 버전을 찾을 수 없습니다.아마도 장래에 이 NuGet 포장은 다른 곳으로 옮겨질 것이다.최근 애플 인사이츠는 InstrumentationKey보다 Connection String의 느낌을 중시하지만 여기.의 기사를 보면 ASP도 본다.Net의 포장 이름이 바뀌었습니다.ASP.Net Core의 경우 본 것 같습니다Connection String.그러나 아까 문서에 따르면 연결열은 새로운Azure의 영역에 필요한 것이기 때문에 컨트롤러 응용에서도 필요하다고 할 수 있다.builder.AddApplicationInsights(InstrumentationKey,
options => { options.IncludeScopes = true; }
);
여기, 방금 전의 범위를 유효하게 하기 위해 설정options => { options.IncludeScopes = true; }했습니다.이 옵션을 사용하지 않으면 로그에 역할 영역이 나타나지 않습니다.
콘솔에서 볼 수 있듯이 더 많은 메타데이터가 증가했다.
DI 사용
사실상 콘솔 앱이라도 DI를 사용하면 같은 효과를 낼 수 있다.Microsoft.Extensions.DependencyInjection 가방 사용ServcieCollection.BuildServiceProvider의 확장 방법을 통해'IServiceProvider의 실례를 얻을 수 있고, 그 중에서 ILogger의 실례를 얻을 수 있기 때문에 어렵지 않다.
흥미로운 점은 services.Configure<TelemetryConfiguration>(config => config.TelemetryChannel = channel); 채널을 겹치는 것이다.이후 TelemetryConfiguration의 구역에서 반짝였다finally.어떤 뜻밖의 엑셉션이 일어났을 때도 플래시를 잘 기록하기 위한 코드다.공식 문서에 이 설명이 실렸다.
DIusing var channel = new InMemoryChannel();
try
{
IServiceCollection services = new ServiceCollection();
services.Configure<TelemetryConfiguration>(config => config.TelemetryChannel = channel);
services.AddLogging(builder =>
{
builder.AddApplicationInsights(InstrumentationKey);
builder.AddJsonConsole(options => options.IncludeScopes = true);
});
IServiceProvider serviceProvider = services.BuildServiceProvider();
ILogger<Program> logger = serviceProvider.GetService<ILogger<Program>>();
using (logger.BeginScope("DI enabled"))
using (logger.BeginScope("start console"))
{
logger.LogInformation(AppLogEvents.Details, "Start Program with {Id} at {RunTime}", 1, DateTime.Now);
try
{
throw new CustomException("tsushi's exception thrown.");
}
catch (CustomException e)
{
logger.LogError(AppLogEvents.Error, e, "Check the host.json configuration.");
}
}
logger.LogInformation(AppLogEvents.Details, "out of scope");
}
finally
{
channel.Flush();
await Task.Delay(TimeSpan.FromMilliseconds(1000));
}
다음번
이번에는 콘솔 애플리케이션으로 동작 검증이나 유닛 테스트 등에 활용할 수 있는 지식으로 AsspNetCore와 포인트를 보고 싶습니다.이번에 소개한 개념 외에도 로그를 필터링하고 업데이트하는 방법을 배워야 한다.
Resource
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.17.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
</ItemGroup>
</Project>
콘솔에서 사용하려면
ILogger 사용할 수 있습니다LoggerFactory.콘솔에 대한 Logging을 실현하려면 Microsoft.Extensions.Logging.Console, ILoggingBuilder에 대해서는 추가AddConsole() 또는 AddJsonConsole()도 가능하다.이번에는 제이슨 출력 포맷을 쓰고 싶어 사용했다AddJsonConsole().이것은dotnet5에서 사용하기 시작한 인터페이스이기 때문에 이번에dotnet5를 스매시에 사용합니다.options의 설정 내용은 뒤에 설명됩니다.이러한 로그 형식에 대한 지원참조할 수 있습니다Console log formatting.
using var loggerFactory = LoggerFactory.Create(builder =>
{
// builder.AddConsole(); // Plain
builder.AddJsonConsole(
options => options.IncludeScopes = true // Enable Scope
); // from net 5; otherwise you need to implement it.
ILogger logger = loggerFactory.CreateLogger<Program>();
logger.LogInformation(AppLogEvents.Details, "Start Program with {Id} at {RunTime}", 1, DateTime.Now);
로그 템플릿 사용
아래 코드를 보면 왜 최신 형식으로 Substite를 쓰지 않는지 생각할 수 있을 거예요.$"{something} is substitution"의 형식.이 형식으로 쓰면 기록을 출력할 때Id = 1,Runtime = DateTime.Now로 개별 항목으로 식별할 수 있다는 이유가 있다.이것은 정식으로 운용할 때 로그를 검색할 때 매우 편리할 것이다.logger.LogInformation(AppLogEvents.Details, "Start Program with {Id} at {RunTime}", 1, DateTime.Now);
또한 AppLogEvents.Details는 맞춤형 클래스로 간단하게 정의int했다.이는 초기 매개 변수가 이벤트 로그 이벤트의 종류를 구별하기 위한 항목이었기 때문입니다.다음 실행 결과에서 "Id":1,"RunTime":"06/26/2021 23:26:07"라는 단독 항목을 확인할 수 있습니다.
log{"EventId":3000,"LogLevel":"Information","Category":"ILoggerSpike.Program","Message":"Start Program with 1 at 06/26/2021 23:26:07","State":{"Message":"Start Program with 1 at 06/26/2021 23:26:07","Id":1,"RunTime":"06/26/2021 23:26:07","{OriginalFormat}":"Start Program with {Id} at {RunTime}"},"Scopes":["simple","start console"]}
Scope 사용
그러면 로그를 유효하게 할 때, 때때로 역할 영역을 정의하려고 합니다.특정한 방법은 호출 창고의 일부분으로 호출되는 것입니까?의 경우다음과 같이 기술하다.이 로그를 출력해 보세요.using (logger.BeginScope("DI enabled"))
using (logger.BeginScope("start console"))
{
logger.LogInformation(AppLogEvents.Details, "Start Program with {Id} at {RunTime}", 1, DateTime.Now);
try
{
throw new CustomException("tsushi's exception thrown.");
}
catch (CustomException e)
{
logger.LogError(AppLogEvents.Error, e, "Check the host.json configuration.");
}
}
logger.LogInformation(AppLogEvents.Details, "out of scope");
"Scopes":["simple","start console"]가 매 도량에 추가됩니다.
log{"EventId":3000,"LogLevel":"Information","Category":"ILoggerSpike.Program","Message":"Start Program with 1 at 06/26/2021 23:26:07","State":{"Message":"Start Program with 1 at 06/26/2021 23:26:07","Id":1,"RunTime":"06/26/2021 23:26:07","{OriginalFormat}":"Start Program with {Id} at {RunTime}"},"Scopes":["simple","start console"]}
{"EventId":3001,"LogLevel":"Error","Category":"ILoggerSpike.Program","Message":"Check the host.json configuration.","Exception":"ILoggerSpike.CustomException: tsushi\u0027s exception thrown. at ILoggerSpike.Program.SimpleConsole() in C:\\Users\\tsushi\\source\\repos\\ILoggerSpike\\ILoggerSpike\\Program.cs:line 81","State":{"Message":"Check the host.json configuration.","{OriginalFormat}":"Check the host.json configuration."},"Scopes":["simple","start console"]}
{"EventId":3000,"LogLevel":"Information","Category":"ILoggerSpike.Program","Message":"out of scope","State":{"Message":"out of scope","{OriginalFormat}":"out of scope"},"Scopes":[]}
Application Insight 사용 ILogger는 인터페이스이며 하나의 실례에서 여러 개의 로그인 공급자에게 출력할 수 있다.이번에는 콘솔을 사용해 애플 인사이트의 공급업체를 사용해 봤다.Microsoft.Extensions.Logging.ApplicationInsights를 NuGet 패키지로 가져오고 ILoggingBuilder에서 다음과 같은 설정을 할 수 있습니다.그나저나 Microsoft.Extensions.Logging.ApplicationInsights 최신2.x도dotnet 5를 위한5.x 버전을 찾을 수 없습니다.아마도 장래에 이 NuGet 포장은 다른 곳으로 옮겨질 것이다.최근 애플 인사이츠는 InstrumentationKey보다 Connection String의 느낌을 중시하지만 여기.의 기사를 보면 ASP도 본다.Net의 포장 이름이 바뀌었습니다.ASP.Net Core의 경우 본 것 같습니다Connection String.그러나 아까 문서에 따르면 연결열은 새로운Azure의 영역에 필요한 것이기 때문에 컨트롤러 응용에서도 필요하다고 할 수 있다.builder.AddApplicationInsights(InstrumentationKey,
options => { options.IncludeScopes = true; }
);
여기, 방금 전의 범위를 유효하게 하기 위해 설정options => { options.IncludeScopes = true; }했습니다.이 옵션을 사용하지 않으면 로그에 역할 영역이 나타나지 않습니다.
콘솔에서 볼 수 있듯이 더 많은 메타데이터가 증가했다.
DI 사용
사실상 콘솔 앱이라도 DI를 사용하면 같은 효과를 낼 수 있다.Microsoft.Extensions.DependencyInjection 가방 사용ServcieCollection.BuildServiceProvider의 확장 방법을 통해'IServiceProvider의 실례를 얻을 수 있고, 그 중에서 ILogger의 실례를 얻을 수 있기 때문에 어렵지 않다.
흥미로운 점은 services.Configure<TelemetryConfiguration>(config => config.TelemetryChannel = channel); 채널을 겹치는 것이다.이후 TelemetryConfiguration의 구역에서 반짝였다finally.어떤 뜻밖의 엑셉션이 일어났을 때도 플래시를 잘 기록하기 위한 코드다.공식 문서에 이 설명이 실렸다.
DIusing var channel = new InMemoryChannel();
try
{
IServiceCollection services = new ServiceCollection();
services.Configure<TelemetryConfiguration>(config => config.TelemetryChannel = channel);
services.AddLogging(builder =>
{
builder.AddApplicationInsights(InstrumentationKey);
builder.AddJsonConsole(options => options.IncludeScopes = true);
});
IServiceProvider serviceProvider = services.BuildServiceProvider();
ILogger<Program> logger = serviceProvider.GetService<ILogger<Program>>();
using (logger.BeginScope("DI enabled"))
using (logger.BeginScope("start console"))
{
logger.LogInformation(AppLogEvents.Details, "Start Program with {Id} at {RunTime}", 1, DateTime.Now);
try
{
throw new CustomException("tsushi's exception thrown.");
}
catch (CustomException e)
{
logger.LogError(AppLogEvents.Error, e, "Check the host.json configuration.");
}
}
logger.LogInformation(AppLogEvents.Details, "out of scope");
}
finally
{
channel.Flush();
await Task.Delay(TimeSpan.FromMilliseconds(1000));
}
다음번
이번에는 콘솔 애플리케이션으로 동작 검증이나 유닛 테스트 등에 활용할 수 있는 지식으로 AsspNetCore와 포인트를 보고 싶습니다.이번에 소개한 개념 외에도 로그를 필터링하고 업데이트하는 방법을 배워야 한다.
Resource
logger.LogInformation(AppLogEvents.Details, "Start Program with {Id} at {RunTime}", 1, DateTime.Now);
{"EventId":3000,"LogLevel":"Information","Category":"ILoggerSpike.Program","Message":"Start Program with 1 at 06/26/2021 23:26:07","State":{"Message":"Start Program with 1 at 06/26/2021 23:26:07","Id":1,"RunTime":"06/26/2021 23:26:07","{OriginalFormat}":"Start Program with {Id} at {RunTime}"},"Scopes":["simple","start console"]}
그러면 로그를 유효하게 할 때, 때때로 역할 영역을 정의하려고 합니다.특정한 방법은 호출 창고의 일부분으로 호출되는 것입니까?의 경우다음과 같이 기술하다.이 로그를 출력해 보세요.
using (logger.BeginScope("DI enabled"))
using (logger.BeginScope("start console"))
{
logger.LogInformation(AppLogEvents.Details, "Start Program with {Id} at {RunTime}", 1, DateTime.Now);
try
{
throw new CustomException("tsushi's exception thrown.");
}
catch (CustomException e)
{
logger.LogError(AppLogEvents.Error, e, "Check the host.json configuration.");
}
}
logger.LogInformation(AppLogEvents.Details, "out of scope");
"Scopes":["simple","start console"]가 매 도량에 추가됩니다.log
{"EventId":3000,"LogLevel":"Information","Category":"ILoggerSpike.Program","Message":"Start Program with 1 at 06/26/2021 23:26:07","State":{"Message":"Start Program with 1 at 06/26/2021 23:26:07","Id":1,"RunTime":"06/26/2021 23:26:07","{OriginalFormat}":"Start Program with {Id} at {RunTime}"},"Scopes":["simple","start console"]}
{"EventId":3001,"LogLevel":"Error","Category":"ILoggerSpike.Program","Message":"Check the host.json configuration.","Exception":"ILoggerSpike.CustomException: tsushi\u0027s exception thrown. at ILoggerSpike.Program.SimpleConsole() in C:\\Users\\tsushi\\source\\repos\\ILoggerSpike\\ILoggerSpike\\Program.cs:line 81","State":{"Message":"Check the host.json configuration.","{OriginalFormat}":"Check the host.json configuration."},"Scopes":["simple","start console"]}
{"EventId":3000,"LogLevel":"Information","Category":"ILoggerSpike.Program","Message":"out of scope","State":{"Message":"out of scope","{OriginalFormat}":"out of scope"},"Scopes":[]}
Application Insight 사용 ILogger는 인터페이스이며 하나의 실례에서 여러 개의 로그인 공급자에게 출력할 수 있다.이번에는 콘솔을 사용해 애플 인사이트의 공급업체를 사용해 봤다.Microsoft.Extensions.Logging.ApplicationInsights를 NuGet 패키지로 가져오고 ILoggingBuilder에서 다음과 같은 설정을 할 수 있습니다.그나저나 Microsoft.Extensions.Logging.ApplicationInsights 최신2.x도dotnet 5를 위한5.x 버전을 찾을 수 없습니다.아마도 장래에 이 NuGet 포장은 다른 곳으로 옮겨질 것이다.최근 애플 인사이츠는 InstrumentationKey보다 Connection String의 느낌을 중시하지만 여기.의 기사를 보면 ASP도 본다.Net의 포장 이름이 바뀌었습니다.ASP.Net Core의 경우 본 것 같습니다Connection String.그러나 아까 문서에 따르면 연결열은 새로운Azure의 영역에 필요한 것이기 때문에 컨트롤러 응용에서도 필요하다고 할 수 있다.builder.AddApplicationInsights(InstrumentationKey,
options => { options.IncludeScopes = true; }
);
여기, 방금 전의 범위를 유효하게 하기 위해 설정options => { options.IncludeScopes = true; }했습니다.이 옵션을 사용하지 않으면 로그에 역할 영역이 나타나지 않습니다.
콘솔에서 볼 수 있듯이 더 많은 메타데이터가 증가했다.
DI 사용
사실상 콘솔 앱이라도 DI를 사용하면 같은 효과를 낼 수 있다.Microsoft.Extensions.DependencyInjection 가방 사용ServcieCollection.BuildServiceProvider의 확장 방법을 통해'IServiceProvider의 실례를 얻을 수 있고, 그 중에서 ILogger의 실례를 얻을 수 있기 때문에 어렵지 않다.
흥미로운 점은 services.Configure<TelemetryConfiguration>(config => config.TelemetryChannel = channel); 채널을 겹치는 것이다.이후 TelemetryConfiguration의 구역에서 반짝였다finally.어떤 뜻밖의 엑셉션이 일어났을 때도 플래시를 잘 기록하기 위한 코드다.공식 문서에 이 설명이 실렸다.
DIusing var channel = new InMemoryChannel();
try
{
IServiceCollection services = new ServiceCollection();
services.Configure<TelemetryConfiguration>(config => config.TelemetryChannel = channel);
services.AddLogging(builder =>
{
builder.AddApplicationInsights(InstrumentationKey);
builder.AddJsonConsole(options => options.IncludeScopes = true);
});
IServiceProvider serviceProvider = services.BuildServiceProvider();
ILogger<Program> logger = serviceProvider.GetService<ILogger<Program>>();
using (logger.BeginScope("DI enabled"))
using (logger.BeginScope("start console"))
{
logger.LogInformation(AppLogEvents.Details, "Start Program with {Id} at {RunTime}", 1, DateTime.Now);
try
{
throw new CustomException("tsushi's exception thrown.");
}
catch (CustomException e)
{
logger.LogError(AppLogEvents.Error, e, "Check the host.json configuration.");
}
}
logger.LogInformation(AppLogEvents.Details, "out of scope");
}
finally
{
channel.Flush();
await Task.Delay(TimeSpan.FromMilliseconds(1000));
}
다음번
이번에는 콘솔 애플리케이션으로 동작 검증이나 유닛 테스트 등에 활용할 수 있는 지식으로 AsspNetCore와 포인트를 보고 싶습니다.이번에 소개한 개념 외에도 로그를 필터링하고 업데이트하는 방법을 배워야 한다.
Resource
builder.AddApplicationInsights(InstrumentationKey,
options => { options.IncludeScopes = true; }
);
사실상 콘솔 앱이라도 DI를 사용하면 같은 효과를 낼 수 있다.
Microsoft.Extensions.DependencyInjection 가방 사용ServcieCollection.BuildServiceProvider의 확장 방법을 통해'IServiceProvider의 실례를 얻을 수 있고, 그 중에서 ILogger의 실례를 얻을 수 있기 때문에 어렵지 않다.흥미로운 점은
services.Configure<TelemetryConfiguration>(config => config.TelemetryChannel = channel); 채널을 겹치는 것이다.이후 TelemetryConfiguration의 구역에서 반짝였다finally.어떤 뜻밖의 엑셉션이 일어났을 때도 플래시를 잘 기록하기 위한 코드다.공식 문서에 이 설명이 실렸다.DI
using var channel = new InMemoryChannel();
try
{
IServiceCollection services = new ServiceCollection();
services.Configure<TelemetryConfiguration>(config => config.TelemetryChannel = channel);
services.AddLogging(builder =>
{
builder.AddApplicationInsights(InstrumentationKey);
builder.AddJsonConsole(options => options.IncludeScopes = true);
});
IServiceProvider serviceProvider = services.BuildServiceProvider();
ILogger<Program> logger = serviceProvider.GetService<ILogger<Program>>();
using (logger.BeginScope("DI enabled"))
using (logger.BeginScope("start console"))
{
logger.LogInformation(AppLogEvents.Details, "Start Program with {Id} at {RunTime}", 1, DateTime.Now);
try
{
throw new CustomException("tsushi's exception thrown.");
}
catch (CustomException e)
{
logger.LogError(AppLogEvents.Error, e, "Check the host.json configuration.");
}
}
logger.LogInformation(AppLogEvents.Details, "out of scope");
}
finally
{
channel.Flush();
await Task.Delay(TimeSpan.FromMilliseconds(1000));
}
다음번
이번에는 콘솔 애플리케이션으로 동작 검증이나 유닛 테스트 등에 활용할 수 있는 지식으로 AsspNetCore와 포인트를 보고 싶습니다.이번에 소개한 개념 외에도 로그를 필터링하고 업데이트하는 방법을 배워야 한다.
Resource
Logging in .NET: Ilogger의 결정 버전 학습
Application Insights Logging with .NET: 애플과의 통합
Logging Providers in .NET: Logging 공급자의 종류와 설정이 적혀 있음
Reference
이 문제에 관하여(Ilogger(1) 이해 - Cole App), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/TsuyoshiUshio@github/items/1ed49c90dc137d55bcfb텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)