EmfSeriLogLogging 1.0.9

dotnet add package EmfSeriLogLogging --version 1.0.9
                    
NuGet\Install-Package EmfSeriLogLogging -Version 1.0.9
                    
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="EmfSeriLogLogging" Version="1.0.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EmfSeriLogLogging" Version="1.0.9" />
                    
Directory.Packages.props
<PackageReference Include="EmfSeriLogLogging" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EmfSeriLogLogging --version 1.0.9
                    
#r "nuget: EmfSeriLogLogging, 1.0.9"
                    
#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.
#:package EmfSeriLogLogging@1.0.9
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EmfSeriLogLogging&version=1.0.9
                    
Install as a Cake Addin
#tool nuget:?package=EmfSeriLogLogging&version=1.0.9
                    
Install as a Cake Tool

EmfSeriLogLogging

NuGet License: MIT

Author / Yazar: Mehmet SEYİTOĞLU
Company / Şirket: EMF BİLGİSAYAR YAZILIM YÖNETİM VE DANIŞMANLIK HİZMETLERİ
Target Framework: .NET 10
License / Lisans: MIT


🇹🇷 Türkçe Dokümantasyon

Genel Bakış

EmfSeriLogLogging, .NET Core uygulamaları için Serilog kütüphanesi ile çoklu log hedefine yapılandırılmış loglama desteği sunan bir kütüphanedir. Console, Dosya (JSON) ve MSSQL Server olmak üzere üç farklı hedefe aynı anda log yazmayı sağlar.

Ne İşe Yarar?

  • Console Log — Uygulama konsoluna renkli log çıktısı
  • File Log — Günlük döndürülen JSON formatında dosya logu
  • MSSQL Log — SQL Server veritabanına yapılandırılmış log kaydı
  • ✅ Otomatik Logs tablosu oluşturma (autoCreateSqlTable)
  • ✅ Kullanıcı adı/e-postası ile log zenginleştirme (UserNameEnricher)
  • ✅ Makine adı ile log zenginleştirme (MachineName)
  • ✅ Yapılandırılabilir log seviyesi
  • ✅ Yapılandırılabilir log dosya yolu
  • ✅ Tek satır kod ile tüm loglama altyapısını kurma

Kurulum

dotnet add package EmfSeriLogLogging

appsettings.json Konfigürasyonu

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=.;Database=MyApp;Trusted_Connection=True;TrustServerCertificate=True"
  },
  "Logging": {
    "LogFilePath": "logs/myapp.json",
    "LogLevel": {
      "Default": "Information"
    }
  }
}

DI Kaydı ve Yapılandırma

// Program.cs

// Tek satırda tüm loglama altyapısını kur
Logger.ConfigureLogging(builder.Services, builder.Configuration);

Özelleştirilmiş bölüm adları ile:

Logger.ConfigureLogging(
    builder.Services,
    builder.Configuration,
    connectionStringSection: "ConnectionStrings:LogDatabase",
    logFilePathSection: "Logging:CustomLogPath",
    logLevelSection: "Logging:LogLevel:Default"
);

Detaylı Kullanım

Otomatik SQL Tablosu

Kütüphane, MSSQL Server'da Logs tablosunu otomatik olarak oluşturur. Tablo şu sütunları içerir:

Sütun Tür Açıklama
Id int Otomatik artan birincil anahtar
Message nvarchar(max) Log mesajı
MessageTemplate nvarchar(max) Log mesaj şablonu
Level nvarchar(128) Log seviyesi (Information, Warning, Error...)
TimeStamp datetime Log zaman damgası
Exception nvarchar(max) Hata detayları
Properties nvarchar(max) Ek özellikler (XML)
UserName nvarchar(128) Giriş yapan kullanıcının adı/e-postası
MachineName nvarchar(128) Uygulama çalıştığı makine adı
Kullanıcı Bilgisi Zenginleştirme

UserNameEnricher, HttpContext üzerinden oturum açmış kullanıcının bilgisini otomatik olarak her log kaydına ekler:

  1. Önce ClaimTypes.Email değerini arar
  2. Bulunamazsa ClaimTypes.Name değerini arar
  3. Hiçbiri bulunamazsa "Anonymous" olarak kaydeder
Controller/Servis İçinde Loglama
public class ProductController : ControllerBase
{
    private readonly ILogger<ProductController> _logger;

    public ProductController(ILogger<ProductController> logger)
    {
        _logger = logger;
    }

    [HttpGet]
    public IActionResult GetProducts()
    {
        _logger.LogInformation("Ürünler listeleniyor...");

        try
        {
            // iş mantığı...
            _logger.LogInformation("Ürünler başarıyla listelendi. Toplam: {Count}", products.Count);
            return Ok(products);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Ürünler listelenirken hata oluştu");
            return StatusCode(500);
        }
    }

    [HttpPost]
    public IActionResult CreateProduct(ProductDto dto)
    {
        _logger.LogInformation("Yeni ürün oluşturuluyor: {ProductName}", dto.Name);

        // ...

        _logger.LogWarning("Ürün fiyatı çok düşük: {Price}", dto.Price);
    }
}

Log Seviyeleri

Seviye Kullanım Alanı
Verbose (Trace) En detaylı log — genelde geliştirme ortamında
Debug Hata ayıklama bilgileri
Information Genel uygulama bilgileri
Warning Dikkat edilmesi gereken durumlar
Error Hata durumları
Fatal Kritik hatalar — uygulama çökmesi

Log Çıktı Hedefleri

Hedef Format Döndürme Politikası
Console Renkli metin -
File JSON Günlük (Daily rolling)
MSSQL Yapılandırılmış tablo Süresiz (veritabanında kalıcı)

🇬🇧 English Documentation

Overview

EmfSeriLogLogging is a logging library for .NET Core applications that provides structured logging support via the Serilog library with multiple log sinks. It simultaneously writes logs to Console, File (JSON), and MSSQL Server.

What Does It Do?

  • Console Log — Colorful output to the application console
  • File Log — Daily rolling JSON formatted file log
  • MSSQL Log — Structured log records to SQL Server database
  • ✅ Automatic Logs table creation (autoCreateSqlTable)
  • ✅ Log enrichment with user name/email (UserNameEnricher)
  • ✅ Log enrichment with machine name (MachineName)
  • ✅ Configurable log level
  • ✅ Configurable log file path
  • ✅ Setup entire logging infrastructure with a single line of code

Installation

dotnet add package EmfSeriLogLogging

appsettings.json Configuration

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=.;Database=MyApp;Trusted_Connection=True;TrustServerCertificate=True"
  },
  "Logging": {
    "LogFilePath": "logs/myapp.json",
    "LogLevel": {
      "Default": "Information"
    }
  }
}

DI Registration and Configuration

// Program.cs

// Setup entire logging infrastructure in a single line
Logger.ConfigureLogging(builder.Services, builder.Configuration);

With custom section names:

Logger.ConfigureLogging(
    builder.Services,
    builder.Configuration,
    connectionStringSection: "ConnectionStrings:LogDatabase",
    logFilePathSection: "Logging:CustomLogPath",
    logLevelSection: "Logging:LogLevel:Default"
);

Detailed Usage

Automatic SQL Table

The library automatically creates the Logs table in MSSQL Server. The table includes the following columns:

Column Type Description
Id int Auto-incrementing primary key
Message nvarchar(max) Log message
MessageTemplate nvarchar(max) Log message template
Level nvarchar(128) Log level (Information, Warning, Error...)
TimeStamp datetime Log timestamp
Exception nvarchar(max) Exception details
Properties nvarchar(max) Additional properties (XML)
UserName nvarchar(128) Authenticated user's name/email
MachineName nvarchar(128) Machine name where the app runs
User Information Enrichment

UserNameEnricher automatically adds the authenticated user's information from HttpContext to every log entry:

  1. First looks for ClaimTypes.Email
  2. If not found, looks for ClaimTypes.Name
  3. If neither is found, records as "Anonymous"
Logging in Controllers/Services
public class ProductController : ControllerBase
{
    private readonly ILogger<ProductController> _logger;

    public ProductController(ILogger<ProductController> logger)
    {
        _logger = logger;
    }

    [HttpGet]
    public IActionResult GetProducts()
    {
        _logger.LogInformation("Listing products...");

        try
        {
            // business logic...
            _logger.LogInformation("Products listed successfully. Total: {Count}", products.Count);
            return Ok(products);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Error occurred while listing products");
            return StatusCode(500);
        }
    }

    [HttpPost]
    public IActionResult CreateProduct(ProductDto dto)
    {
        _logger.LogInformation("Creating new product: {ProductName}", dto.Name);

        // ...

        _logger.LogWarning("Product price is too low: {Price}", dto.Price);
    }
}

Log Levels

Level Usage
Verbose (Trace) Most detailed log — typically in development
Debug Debugging information
Information General application information
Warning Situations requiring attention
Error Error conditions
Fatal Critical errors — application crashes

Log Output Sinks

Sink Format Rolling Policy
Console Colored text -
File JSON Daily rolling
MSSQL Structured table Permanent (persisted in database)

API Reference / API Referansı

Class Description (EN) Açıklama (TR)
Logger (static) Static class to configure Serilog logging Serilog loglamayı yapılandırmak için statik sınıf
Logger.ConfigureLogging() Sets up Console, File and MSSQL sinks Console, File ve MSSQL hedeflerini yapılandırır
UserNameEnricher Log enricher for user identity Kullanıcı kimliği için log zenginleştirici

Method Signature / Metot İmzası

public static void ConfigureLogging(
    IServiceCollection services,
    IConfiguration configuration,
    string connectionStringSection = "ConnectionStrings:DefaultConnection",
    string logFilePathSection = "Logging:LogFilePath",
    string logLevelSection = "Logging:LogLevel:Default"
)
Parameter Default Description (EN) Açıklama (TR)
services - DI service collection DI servis koleksiyonu
configuration - Application configuration Uygulama yapılandırması
connectionStringSection "ConnectionStrings:DefaultConnection" Config section for connection string Connection string yapılandırma bölümü
logFilePathSection "Logging:LogFilePath" Config section for log file path Log dosya yolu yapılandırma bölümü
logLevelSection "Logging:LogLevel:Default" Config section for minimum log level Minimum log seviyesi yapılandırma bölümü

Dependencies / Bağımlılıklar

  • Serilog (4.3.1)
  • Serilog.AspNetCore (10.0.0)
  • Serilog.Sinks.Console (6.1.1)
  • Serilog.Sinks.File (7.0.0)
  • Serilog.Sinks.MSSqlServer (9.0.3)
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows 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.9 116 4/27/2026
1.0.8 106 4/20/2026
1.0.7 115 3/16/2026
1.0.6 209 7/27/2025
1.0.5 218 1/30/2025
1.0.4 221 9/9/2024
1.0.3 182 7/25/2024
1.0.2 177 7/9/2024
1.0.1 216 7/9/2024
1.0.0 200 7/9/2024

SeriLog Kütüphanesi Entegrasyonu ile FileLog, ConsoleLog, MsSqlLog.