DontPanicLabs.Ifx.Telemetry.Logger.Serilog
2.0.0
Prefix Reserved
dotnet add package DontPanicLabs.Ifx.Telemetry.Logger.Serilog --version 2.0.0
NuGet\Install-Package DontPanicLabs.Ifx.Telemetry.Logger.Serilog -Version 2.0.0
<PackageReference Include="DontPanicLabs.Ifx.Telemetry.Logger.Serilog" Version="2.0.0" />
<PackageVersion Include="DontPanicLabs.Ifx.Telemetry.Logger.Serilog" Version="2.0.0" />
<PackageReference Include="DontPanicLabs.Ifx.Telemetry.Logger.Serilog" />
paket add DontPanicLabs.Ifx.Telemetry.Logger.Serilog --version 2.0.0
#r "nuget: DontPanicLabs.Ifx.Telemetry.Logger.Serilog, 2.0.0"
#:package DontPanicLabs.Ifx.Telemetry.Logger.Serilog@2.0.0
#addin nuget:?package=DontPanicLabs.Ifx.Telemetry.Logger.Serilog&version=2.0.0
#tool nuget:?package=DontPanicLabs.Ifx.Telemetry.Logger.Serilog&version=2.0.0
DontPanicLabs.Ifx.Telemetry.Logger.Serilog
A Serilog-based implementation of DontPanicLabs.Ifx.Telemetry.Logger.Contracts.ILogger with support for multiple
logging destinations.
Features
- Multiple Sinks: Configure one or more logging destinations (SQL Server, File, Console, and 100+ community sinks)
- Minimal Dependencies: Core package includes only Serilog runtime; consumers add references to desired sinks
Installation
Install the core logging package:
dotnet add package DontPanicLabs.Ifx.Telemetry.Logger.Serilog
IMPORTANT: You must also install the Serilog sink packages you want to use. The core package does not include any sinks.
For example, to use SQL Server, File, and Console sinks:
dotnet add package Serilog.Sinks.MSSqlServer
dotnet add package Serilog.Sinks.File
dotnet add package Serilog.Sinks.Console
Configuration
This logger can either be configured programmatically or via application configuration (appsettings.json, environment variables, etc).
Configuration Format
This logger uses Serilog's native configuration format. Configure your logger using one of the following options:
App Settings / Environment Variables-based configuration:
Configure one or more logging sinks by adding standard
serilog settings for the sink in your app settings under ifx:telemetry:logging:serilog.
Specify Serilog configuration programmatically:
The Logger also exposes a constructor that accepts a string representing the Serilog configuration in JSON format.
var logger = new Logger(serilogJsonConfig);
where serilogJsonConfig is a string containing the Serilog configuration whose structure is the same as what would be
in ifx:telemetry:logging:serilog:
{
"MinimumLevel": "Debug",
"WriteTo": [ "Console" ],
...
}
Single Sink Example (SQL Server)
This sample configuration configures logging to SQL server. The columnOptionsSection shown here configures writing
the metrics and properties IDictionary<string, object> parameters passed to the logging methods to be written
as JSON to the LogEvent column in the SQL table. If columnOptionsSection is not specified, the default Serilog
behavior writes this data as XML in the Properties column.
{
"ifx": {
"telemetry": {
"logging": {
"serilog": {
"Using": ["Serilog.Sinks.MSSqlServer"],
"MinimumLevel": "Verbose",
"WriteTo": [
{
"Name": "MSSqlServer",
"Args": {
"connectionString": "{YOUR SQL CONNECTION STRING HERE}",
"sinkOptionsSection": {
"tableName": "Logs",
"schemaName": "dbo",
"autoCreateSqlTable": true,
"batchPostingLimit": 50,
"batchPeriod": "0.00:00:05"
},
"columnOptionsSection": {
"addStandardColumns": ["LogEvent"],
"removeStandardColumns": ["Properties"],
"logEvent": {
"excludeStandardColumns": true
}
}
}
}
]
}
}
}
}
}
Multiple Sinks Example
Log to a rolling file log and the console, both using JSON formatting to display structured log data.
{
"ifx": {
"telemetry": {
"logging": {
"serilog": {
"Using": ["Serilog.Sinks.File", "Serilog.Sinks.Console"],
"MinimumLevel": "Verbose",
"WriteTo": [
{
"Name": "File",
"Args": {
"formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog",
"path": "logs/app-.log",
"rollingInterval": "Day",
"retainedFileCountLimit": 7
}
},
{
"Name": "Console",
"Args": {
"formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog"
}
}
]
}
}
}
}
}
Usage
Basic Setup
// Create the logger (automatically loads configuration from appsettings.json); namespaces shown in-line for clarity.
// Consuming code should instantiate the logger but use the `ILogger` interface to interact.
DontPanicLabs.Ifx.Telemetry.Logger.Contracts.ILogger logger = new DontPanicLabs.Ifx.Telemetry.Logger.Serilog.Logger();
// Use the logger
logger.Log("Application started", SeverityLevel.Information, null);
| Product | Versions 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. |
-
net10.0
- DontPanicLabs.Ifx.Configuration.Contracts (>= 2.0.0)
- DontPanicLabs.Ifx.Configuration.Local (>= 2.0.0)
- DontPanicLabs.Ifx.Telemetry.Logger.Contracts (>= 2.0.0)
- Serilog (>= 4.2.0)
- Serilog.Settings.Configuration (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.