basic05
basic_04์์ ๋ก๊ฑฐ๋ฅผ ํ์ค์์ ZLogger๋ก ๋ณ๊ฒฝ๋์์ต๋๋ค. ZLogger์ ๋ํ ์ค๋ช ์ ๊ต์ก์์ ์ ๊ณตํด์ฃผ์ [ํ์ต > 05_ZLogger.md]์ ๋งค์ฐ ์ ์ ๋ฆฌ๋์ด์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ ํด๋น ์๋ฃ๋ฅผ ์ดํด๋ณด์๋ ๊ฒ๋ค ๊ถํฉ๋๋ค.
ZLogger๋?
๋ก๊น ์ ์ํ ํ์ฅ(extension) ๋ผ์ด๋ธ๋ฌ๋ฆฌ
ํ์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ Logger๋ Console.Write()๋ณด๋ค ๋ ๊ฐ๋ณ๊ฒ ๋ง๋ค์ด์ ธ์ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ถํ๋ฅผ ์ค์ผ ์ ์์
๋ก๊ทธ ์ถ๋ ฅ์ ํ์ผ์ ํด์ค ์ ์์ผ๋ฉฐ, ํ์ผ ์ด๋ฆ๋ ๋์ ์ผ๋ก ์์ฑํ์ฌ ๋ง๋ค์ด ์ค ์ ์์
Nuget์์ ZLogger๋ฅผ ๋ค์ด๋ฐ์ ์ ์์
// program.cs์์ logging ์ค์ using Zlogger; var builder = WebApplication.CreateBuilder(args); // ๊ธฐ๋ณธ ์ ๊ณต์๋ฅผ ์ฌ์ ์ํด์ค๋ค. builder.logging.ClearProviders(); // optional(MS.E.Logging): default๊ฐ์ Info์ด๋ฉฐ option์ ๋ฐ๊ฟ ์ต์ ๋ก๊ทธ๋ ๋ฒจ์ ์ง์ ํด ์ค ์ ์๋ค. builder.logging.SetMinimumLevel(LogLevel.Debug); // ์ฝ์์ ์ถ๋ ฅํ๋ค. builder.logging.AddZLoggerConsole(); // ์ง์ ๋ ํ์ผ์ ์ถ๋ ฅํ๋ค. builder.logging.AddZLoggerFile("fileName.log"); // ๋ ์ง-์๊ฐ ๋๋ ํ์ผ ํฌ๊ธฐ์ ๋ฐ๋ผ ์ถ๋ ฅ ํ์ผ ๊ฒฝ๋ก๋ฅผ ๋ณ๊ฒฝํ๋ค. builder.logging.AddZLoggerRollingFile((dt, x) => $"logs/{dt.ToLocalTime():yyyy-MM-dd}_{x:000}.log", x => x.ToLocalTime().Date, 1024); // ๊ตฌ์กฐํ๋ ๋ก๊น ์ง์ builder.logging.AddZLoggerConsole(options => { options.EnableStructuredLogging = true; });
ZLogger ์ฌ์ฉ ํ
์คํธ

program.cs์ ๋ก๊ฑฐ ์ถ๋ ฅ ์ถ๊ฐ
AddZLoggerConsole()์ ์ฝ์์ ์ถ๋ ฅํด์ฃผ๊ณ , AddZLoggerFile("ํ์ผ๋ช ")์ ํ์ผ์ ์ถ๋ ฅํด์ค
Last updated