Simplifier.Serilog
1.0.4
dotnet add package Simplifier.Serilog --version 1.0.4
NuGet\Install-Package Simplifier.Serilog -Version 1.0.4
<PackageReference Include="Simplifier.Serilog" Version="1.0.4" />
<PackageVersion Include="Simplifier.Serilog" Version="1.0.4" />
<PackageReference Include="Simplifier.Serilog" />
paket add Simplifier.Serilog --version 1.0.4
#r "nuget: Simplifier.Serilog, 1.0.4"
#:package Simplifier.Serilog@1.0.4
#addin nuget:?package=Simplifier.Serilog&version=1.0.4
#tool nuget:?package=Simplifier.Serilog&version=1.0.4
Simplifier For Serilog
Provides simple way to get Serilog Up and running with additional extensions to Serilog API enhancing logging experience.
Enhancements
You get all the features of Serilog + the following
- Enriches the logs with additional details, i.e Namespace Name, Class name and Function name.
- Enriches the logs enabling applications to measure time consumed by each methods at the instant of logging. (10ms in the example denotes that the function has spend 10ms until it reaches the log statement)
- Enriches the logs with In-Out Logs. This allows detailed tracing of each functions enter and exit traces.
- Provides various API's to conditionally write the log, reducing complexity in the calling code and log file size.
- Zero Setup required as the Logging configuration templates are shipped out of the box
Quick Start
Add the nuget package to your project either via nuget explorer or by running dotnet add package Simplifier.Serilog
The following code will log a single Information Trace in a pre-defined format to MyApplication_YYYYMMDD.slog. The file will be created in the working directory of the executing application.
using (LogScope aScope = new LogScope(new LoggerDetail("DemoUnOptimizedLogger")))
{
aScope.Info("Hello From Serilogger");
}
However the above example can further be optimized to reuse LoggingDetail and infact one LogScope can be used to log multiple log statements at once. A more realistic example is shown below.
namespace Simplifier.Serilog.Sample
{
public class DemoClass
{
// Declare the logger detail in the class
private static readonly LoggerDetail myLoggerDetail = new LoggerDetail(typeof(DemoClass));
public void Execute()
{
// Log the required info by creation LogScope withing class methods
using (LogScope aScope = new LogScope(new LoggerDetail(this.GetType())))
{
aScope.Info("Processing execute request for a total of 408 items.");
// Do Work
aScope.Warning("Connection returned with busy status, retrying...");
// Do Work
aScope.Error("Connection timed out, execute failed");
// Do Work
aScope.Fatal("Critical error during execute function.");
}
}
}
}
Runtime Switches
1.LoggingSetup.ChangeLogLevel(); allows the application to change the Log Verbosity at runtime.
1.LoggingSetup.InOutEnabled allows the application to dump IN-OUT traces at runtime.
Default Configuration
The default configuration used LoggingConfiguration.ProdConfig which equates to Informational and higher level logs will be written to MyApplication_.log, which rolls over every day upto 14 days, After which the oldest file will be deleted.
public static LoggingConfiguration ProdConfig => new LoggingConfiguration()
{
EnableConsole = false,
FileName = LoggingSetup.DefaultLogFileName,
RollingInterval = RollingInterval.Day,
RetentionFileCountLimit = 14,
LogFormat = LoggingSetup.DefaultLogFormat,
LogEventLevel = LogEventLevel.Information,
MultiProcess = true
};
Log Format
By default the log file will produce the following columns
| Column Number | Name | Description |
|---|---|---|
| 1 | Date | Standard Date Column |
| 2 | Time | Standard Local Time Column |
| 3 | Level | 3 Character, Serilog Trace Level. |
| 4 | ThreadID | ID Of the executing thread |
| 5 | Executing Time | Time consumed prior to reaching the trace statement. |
| 6 | CallSite | Namespace + Function Name of the logger |
| 7 | Log | The full log as written by the application |
Customization and Configurations
The library has few preset templates which are present in LoggingConfiguration as static members.
However, library provides allows the consumers to change multiple settings as per the need and this is achieved by invoking LoggingSetup.Create(new LoggingConfiguration() { <Set the Properties as required> });, ensure that this call is made at the startup of the application before any logs are written.
Changelog
1.0.4
- Upgrade serilog version to 4.3.1
- Fixed bug where Error API was logging at Fatal Level
1.0.3
Added Overloads for all the API's to accept exception object
1.0.2
- Added documentation to the nuget package.
- Changed Default Log Format to provide 60 Characters for Callsite.
1.0.1
Changed LogScope to class to improve compatibility.
1.0.0
Initial release
| Product | Versions 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 is compatible. 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 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. |
| .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 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 is compatible. 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. |
-
.NETFramework 4.7.2
- Serilog (>= 4.3.1)
- Serilog.Enrichers.Process (>= 3.0.0)
- Serilog.Enrichers.Thread (>= 4.0.0)
- Serilog.Sinks.Console (>= 6.1.1)
- Serilog.Sinks.File (>= 7.0.0)
-
.NETFramework 4.8
- Serilog (>= 4.3.1)
- Serilog.Enrichers.Process (>= 3.0.0)
- Serilog.Enrichers.Thread (>= 4.0.0)
- Serilog.Sinks.Console (>= 6.1.1)
- Serilog.Sinks.File (>= 7.0.0)
-
.NETStandard 2.0
- Serilog (>= 4.3.1)
- Serilog.Enrichers.Process (>= 3.0.0)
- Serilog.Enrichers.Thread (>= 4.0.0)
- Serilog.Sinks.Console (>= 6.1.1)
- Serilog.Sinks.File (>= 7.0.0)
-
.NETStandard 2.1
- Serilog (>= 4.3.1)
- Serilog.Enrichers.Process (>= 3.0.0)
- Serilog.Enrichers.Thread (>= 4.0.0)
- Serilog.Sinks.Console (>= 6.1.1)
- Serilog.Sinks.File (>= 7.0.0)
-
net10.0
- Serilog (>= 4.3.1)
- Serilog.Enrichers.Process (>= 3.0.0)
- Serilog.Enrichers.Thread (>= 4.0.0)
- Serilog.Sinks.Console (>= 6.1.1)
- Serilog.Sinks.File (>= 7.0.0)
-
net8.0
- Serilog (>= 4.3.1)
- Serilog.Enrichers.Process (>= 3.0.0)
- Serilog.Enrichers.Thread (>= 4.0.0)
- Serilog.Sinks.Console (>= 6.1.1)
- Serilog.Sinks.File (>= 7.0.0)
-
net9.0
- Serilog (>= 4.3.1)
- Serilog.Enrichers.Process (>= 3.0.0)
- Serilog.Enrichers.Thread (>= 4.0.0)
- Serilog.Sinks.Console (>= 6.1.1)
- Serilog.Sinks.File (>= 7.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.
1. Upgrade serilog version to 4.3.1
2. Fixed bug where Error API was logging at Fatal Level