728x90
728x170
> Serilog 적용하기
1. 콘솔 프로젝트 생성(.NET 6.0)
2. Nuget 설치
Serilog.Sinks.Console
Serilog.Sinks.File
3. Log 설정
using Serilog;
using Serilog.Core;
namespace SerilogTest;
class Program
{
static void Main(string[] args)
{
var levelSwitch = new LoggingLevelSwitch();
Log.Logger = new LoggerConfiguration()
// 최소 지정 로그 레벨 : Info 레벨 이상 로그를 기록한다는 의미
.MinimumLevel.Information()
// 콘솔에도 내용을 남김
.WriteTo.Console()
//파일로 기록할 로그 파일명을 입력
.WriteTo.File(@"c:\log\log.txt", rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: true)
.CreateLogger();
for (int idx = 0; idx < 100; idx++)
{
Log.Information($"{idx} - Serilog Test");
}
Log.CloseAndFlush();
}
}
4. 결과
> Seq 연동하기
1. Seq 설치
https://datalust.co/download
2. 설치 후 관리자 설정
Browse Seq 버튼을 클릭하면 웹이사이트가 열리고 아까 지정한 아이디와 비밀번호를 입력한다.
3. Seq 설정을 끝났고 프로젝트에 Nuget 설치
Serilog.Sinks.Seq
4. Serilog 를 이용해 Seq 연동
.WriteTo.Seq("http://localhost:5341") 코드를 추가하면된다.
using Serilog;
using Serilog.Core;
namespace SerilogTest;
class Program
{
static void Main(string[] args)
{
var levelSwitch = new LoggingLevelSwitch();
Log.Logger = new LoggerConfiguration()
// 최소 지정 로그 레벨 : Info 레벨 이상 로그를 기록한다는 의미
.MinimumLevel.Information()
// 콘솔에도 내용을 남김
.WriteTo.Console()
//파일로 기록할 로그 파일명을 입력
.WriteTo.File(@"c:\log\log.txt", rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: true)
// Seq 에 로그 정보 입력
.WriteTo.Seq("http://localhost:5341", controlLevelSwitch: levelSwitch)
.CreateLogger();
for (int idx = 0; idx < 100; idx++)
{
Log.Information($"{idx} - Serilog Test");
}
Log.CloseAndFlush();
}
}
프로그램을 실행하고 웹사이트를 리프레쉬하면 아래처럼 로그 내용이 보여지게된다.
소스
https://github.com/kei-soft/KJunBlog/tree/master/SerilogTest
728x90
그리드형
'C# > Winform' 카테고리의 다른 글
[C#] global using (0) | 2022.06.15 |
---|---|
[C#] null 허용 관련 에러 없애기 (0) | 2022.06.05 |
[C#] Visual Studio 2022 에서 Console.WriteLine 내용이 출력창에 나타나지 않을때 (0) | 2022.05.14 |
[C#] ILSpay (ICSharpCode) 디컴파일러 (0) | 2022.05.11 |
[C#] MessageBox.Show TopMost true 로 띄우기 (0) | 2022.05.10 |