JDLogger 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package JDLogger --version 1.0.0                
NuGet\Install-Package JDLogger -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JDLogger" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JDLogger --version 1.0.0                
#r "nuget: JDLogger, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install JDLogger as a Cake Addin
#addin nuget:?package=JDLogger&version=1.0.0

// Install JDLogger as a Cake Tool
#tool nuget:?package=JDLogger&version=1.0.0                

JDLogger

.NET 애플리케이션을 위한 경량화된 SQLite 기반의 로깅 라이브러리입니다.

프로그램 로깅과 데이터 로깅을 모두 지원하며, 구조화된 로그 데이터를 쉽게 저장하고 조회할 수 있습니다.

주요 기능

  • SQLite 기반의 영구 저장소
  • 계층적 로깅 스코프 지원
  • 구조화된 로그 데이터 저장
  • 예외 정보의 상세한 기록
  • 다양한 형식(CSV 등)으로 로그 내보내기
  • 커스텀 로그 모델 지원
  • 손쉬운 예외 처리 및 로깅
  • Thread-Safe하게 설계된 로깅

시작하기

설치

dotnet add package JDLogger

초기화

// 기본 초기화
JDLogger.Initialize("my_log.db");

// 커스텀 매퍼와 함께 초기화
JDLogger.Initialize("my_log.db", new[] { 
    new ProductLogMapper()
});

사용 예제

1. 기본적인 로깅

static void ApplicationLogExample()
{
    var log = JDLogger.BeginScope<Program>();
    log.Log(LogLevel.Information, "프로그램 시작");
    
    // 로그 조회 및 내보내기
    log.Where(entity => entity.Level == LogLevel.Information)
       .Export("log.csv", JDLoggerFormatter.Csv);
}

2. 커스텀 데이터 로깅

static void ProductLogExample()
{
    var log = JDLogger.BeginScope<TestSequence>();
    
    var productLog = new ProductLog
    {
        LotId = "LOT001",
        ProductName = "TestProduct",
    };
    log.Log(productLog);
}

3. 예외 처리 및 로깅

static void UseTryCatchExample()
{
    var log = JDLogger.BeginScope<TestSequence>();
    
    // 자동 예외 로깅
    log.TryCatch(() =>
    {
        string[] s = ["a", "b", "c"];
        for (int i = 0; i < 100; i++)
        {
            Console.WriteLine(s[i]); // will throw exception
        }
    }, "indexReferenceJob", continue: true);

    // 오늘 발생한 에러 로그 조회
    foreach (var ex in log.All().Today().Where(entity => entity.Level == LogLevel.Error))
    {
        Console.WriteLine(ex.ExceptionData);
    }
}

4. 객체 상태 덤프

static void UseDumpExample()
{
    var log = JDLogger.BeginScope<DumpExample>();
    
    // 객체 상태 덤프
    var settings = new AppSettings() { Identifier = "Test" };
    log.Dump(settings, LogLevel.Critical, message: "객체 상태 덤프");
    
    // 예외 덤프
    try
    {
        throw new NullReferenceException("Exception 데이터 덤프 예제");
    }
    catch (Exception ex)
    {
        log.Dump(ex);
    }
}

로그 조회를 위한 확장 메서드

시간 기반 필터링

// 오늘 기록된 로그만 조회
var todayLogs = log.All().Today();

// 특정 기간의 로그 조회
var lastWeekLogs = log.All().Between(
    DateTime.Now.AddDays(-7), 
    DateTime.Now
);

로그 레벨 필터링

// 에러 로그만 조회
var errorLogs = log.All().OfLevel(LogLevel.Error);

// 크리티컬 로그만 조회 후 CSV로 내보내기
log.All()
   .OfLevel(LogLevel.Critical)
   .Export("critical-logs.csv", JDLoggerFormatter.Csv);

최근 로그 조회

// 최근 100개의 로그 조회
var recentLogs = log.All().Recent(100);

// 최근 10개의 에러 로그 조회
var recentErrors = log.All()
    .OfLevel(LogLevel.Error)
    .Recent(10);

필터 조합하기

// 오늘 발생한 에러 중 최근 5개만 조회
var recentTodayErrors = log.All()
    .Today()
    .OfLevel(LogLevel.Error)
    .Recent(5);

// 지난 주의 크리티컬 로그를 CSV로 내보내기
log.All()
   .Between(DateTime.Now.AddDays(-7), DateTime.Now)
   .OfLevel(LogLevel.Critical)
   .Export("last-week-critical.csv", JDLoggerFormatter.Csv);

커스텀 로그 모델

사용자 정의 로그 모델을 생성하여 특정 도메인의 데이터를 로깅할 수 있습니다:

public class ProductLog : ILogModel
{
    public string Class { get; set; }
    public LogLevel Level { get; set; }
    public DateTime Time { get; set; }
    public string LotId { get; set; }
    public string ProductName { get; set; }
}

로그 내보내기

로그를 다양한 형식으로 내보낼 수 있습니다:

// CSV로 내보내기
log.All().Export("logs.csv", JDLoggerFormatter.Csv);

// 헤더를 지정해서 CSV로 내보내기
log.All().Export("logs.csv", new CsvLogFormatter("a,b,c,d,e,f"));

// Json로 내보내기
log.All().Export("logs.csv", JDLoggerFormatter.Json);

// Tab(\t)로 구분된 포멧터로 내보내기
log.All().Export("logs.txt", JDLoggerFormatter.Tabs);

// 헤더를 지정해서서 Tab(\t)로 구분된 포멧터로 내보내기
log.All().Export("logs.txt", new TabDelimitedFormatter("a\tb\tc\td\te\tf"));

// 커스텀 포맷터 사용
var customFormatter = new CustomLogFormatter();
log.All().Export("logs.txt", customFormatter);
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.6 87 11/21/2024
1.0.5 82 11/18/2024
1.0.4 92 11/14/2024
1.0.3 84 11/14/2024
1.0.2 87 11/13/2024
1.0.1 98 11/13/2024
1.0.0 92 11/13/2024