TCIS.Logging.Serilog 1.1.3

dotnet add package TCIS.Logging.Serilog --version 1.1.3
                    
NuGet\Install-Package TCIS.Logging.Serilog -Version 1.1.3
                    
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="TCIS.Logging.Serilog" Version="1.1.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TCIS.Logging.Serilog" Version="1.1.3" />
                    
Directory.Packages.props
<PackageReference Include="TCIS.Logging.Serilog" />
                    
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 TCIS.Logging.Serilog --version 1.1.3
                    
#r "nuget: TCIS.Logging.Serilog, 1.1.3"
                    
#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 TCIS.Logging.Serilog@1.1.3
                    
#: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=TCIS.Logging.Serilog&version=1.1.3
                    
Install as a Cake Addin
#tool nuget:?package=TCIS.Logging.Serilog&version=1.1.3
                    
Install as a Cake Tool

TCIS.Logging.Serilog

ECS service.environment uses the shared environment resolution policy: immutable assembly master/image suffix, explicit service configuration, explicit deployment environment variables, then unset. Bootstrap and runtime formatting do not infer prod from the host's implicit Production default.

A provider that integrates Serilog into the TCIS logging system.

🌟 Overview

This module automatically configures Serilog as the primary logging provider for the entire application, replacing the default Microsoft logging. It allows you to easily route logs to storage systems such as Elasticsearch, Seq, or Files with flexible formats (e.g., JSON).

📦 Installation

Install the package via NuGet or .NET CLI:

dotnet add package TCIS.Logging.Serilog

⚙️ Configuration (appsettings.json)

Standard Serilog configuration (Sinks, Enrichers, etc.):

{
  "Serilog": {
    "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "Warning",
        "System": "Warning"
      }
    },
    "WriteTo": [
      {
        "Name": "Console",
        "Args": {
          "formatter": "TCIS.Logging.Serilog.TCISEcsJsonFormatter, TCIS.Logging.Serilog"
        }
      },
      {
        "Name": "File",
        "Args": {
          "path": "Logs/log-.txt",
          "rollingInterval": "Day",
          "formatter": "TCIS.Logging.Serilog.TCISEcsJsonFormatter, TCIS.Logging.Serilog"
        }
      }
    ],
    "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
  }
}

⚠️ formatter is mandatory on every sink, and it must be TCISEcsJsonFormatter.

MicrosoftLoggingSink emits log records as "{@TCISEcsDocument}", and AddTSerilog registers Destructure.AsScalar<TcisEcsDocument>() so the object reaches the formatter intact — TCISEcsJsonFormatter then calls the Elastic SDK's own Serialize().

Any sink without that formatter — including the plain console sink and CompactJsonFormatter, which this README previously showed — renders the scalar through ToString(). Before 22/10/2026 every line came out as the literal string TCIS.Logging.TcisEcsDocument: message, exception and stack trace were all gone — measured on a generated project, where it hid the real cause of a 500 for several runs. ToString() now returns the ECS JSON, so content survives, but such a sink still wraps it in its own template and renders framework logs as plain, unmasked text. Keep the formatter on every sink.

🚀 Usage

In Program.cs, call AddTSerilog() — on WebApplicationBuilder, or on a worker's HostApplicationBuilder (overload for IHostApplicationBuilder, since 22/10/2026).

When Serilog writes to the console (no Serilog:WriteTo declared, or a Console sink at any depth), AddTSerilog removes only Microsoft's ConsoleLoggerProvider — otherwise every record reaches stdout twice. Every other provider (Debug, EventSource, EventLog, anything the host added) is kept. When Serilog does not write to the console (for example a File sink only), Microsoft's console stays, so the host's stdout is unchanged.

The package references Microsoft.AspNetCore.App (for the WebApplicationBuilder overload), so a worker must run on the mcr.microsoft.com/dotnet/aspnet image, not dotnet/runtime.

using TCIS.Logging.Serilog.Extensions;

var builder = WebApplication.CreateBuilder(args);

// Configure Serilog to replace Microsoft Logging
builder.AddTSerilog();

var app = builder.Build();
app.Run();

Worker host (Host.CreateApplicationBuilder — Hangfire server, background jobs):

HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
builder.Services.AddTLogging(builder.Configuration);   // pass configuration, or TLogSettings is ignored
builder.Services.AddExceptionClassification();
builder.AddTSerilog();
await builder.Build().RunAsync();

A worker that calls only AddTLogging() without AddTSerilog() sends records to the default Microsoft console provider. Before 22/10/2026 every such line read TCIS.Logging.TcisEcsDocument; TcisEcsDocument.ToString() now renders the ECS JSON, but framework logs (Hangfire, EF Core) stay plain text — call AddTSerilog().

Classifying exceptions logged by third-party libraries

Polly, Hangfire and Microsoft.* log through ILogger, not ITCISLogger, so TLogWriter never classifies them. When the host registers a classifier (AddExceptionClassification() plus its own IExceptionClassifierRules), AddTSerilog classifies those records with that classifier — any sink, including one declared in Serilog:WriteTo — instead of writing error.code: "SYS-UNK-9999", retryable: false. Without a registered classifier nothing changes.

Records through ITCISLogger Unchanged — already classified by TLogWriter
Records written before the host is built Still unclassified — no classifier exists yet
A consumer rule that throws The record is still written, unclassified (Serilog contains enricher failures)
Several hosts in one process Each uses its own classifier

Since 30/10/2026 (RFC-0007). A host that builds Serilog itself instead of calling AddTSerilog adds the same enrichment:

hostBuilder.UseSerilog((context, services, logger) => logger
    .ReadFrom.Configuration(context.Configuration)
    .Enrich.WithTExceptionClassification(services));

category: "Unknown" on an error record means no rule matched — alert on it rather than treating it as harmless.

💡 Basic Example

After adding AddTSerilog(), all logging calls from TCIS.Logging (via ILogWriter) will be automatically handled and enriched by Serilog. You simply continue to use ILogWriter as usual.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
.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 (1)

Showing the top 1 NuGet packages that depend on TCIS.Logging.Serilog:

Package Downloads
TCIS.Logging.Hosting

One-call TCIS application logging composition, startup lifecycle and downstream failure attribution.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.3 86 11/11/2026
1.1.2 102 11/10/2026
1.1.1 108 11/9/2026
1.1.0 104 11/7/2026
1.0.9 116 11/5/2026
1.0.9-rc.2 68 11/5/2026
1.0.9-rc.1 70 11/4/2026
1.0.8 118 11/3/2026
1.0.8-rc.11 81 10/30/2026
1.0.8-rc.10 72 10/30/2026
1.0.8-rc.9 75 10/30/2026
1.0.8-rc.8 81 10/29/2026
1.0.8-rc.7 75 10/27/2026
1.0.8-rc.6 81 10/27/2026
1.0.8-rc.5 75 10/23/2026
1.0.8-rc.4 80 10/23/2026
1.0.8-rc.3 71 10/23/2026
1.0.8-rc.2 72 10/22/2026
1.0.8-rc.1 73 10/22/2026
1.0.7 132 10/22/2026
Loading failed