Serilog.Sinks.RollingFile.Extension 2.0.2

dotnet add package Serilog.Sinks.RollingFile.Extension --version 2.0.2                
NuGet\Install-Package Serilog.Sinks.RollingFile.Extension -Version 2.0.2                
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="Serilog.Sinks.RollingFile.Extension" Version="2.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Serilog.Sinks.RollingFile.Extension --version 2.0.2                
#r "nuget: Serilog.Sinks.RollingFile.Extension, 2.0.2"                
#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 Serilog.Sinks.RollingFile.Extension as a Cake Addin
#addin nuget:?package=Serilog.Sinks.RollingFile.Extension&version=2.0.2

// Install Serilog.Sinks.RollingFile.Extension as a Cake Tool
#tool nuget:?package=Serilog.Sinks.RollingFile.Extension&version=2.0.2                

Serilog.Sinks.SizeRollingFile Build status

This project has been developed to extend Serilog buit-in RollingFile, to limit the log files based on size, also purge old files to free up disk space.

The nuget package NuGet Status

https://www.nuget.org/packages/Serilog.Sinks.RollingFile.Extension/

PM> Install-Package Serilog.Sinks.RollingFile.Extension

Configuring the logger

1. Through the code

new LoggerConfiguration()                                       
      .WriteTo.SizeRollingFile(@"C:\temp\log.txt", 
              retainedFileDurationLimit: TimeSpan.FromDays(2), 
              fileSizeLimitBytes: 1024 * 1024 * 10) // 10MB
      .CreateLogger();

2. Configuration file

XML appsettings.json configuration
<appSettings>
    <add key="serilog:using:SizeRollingFile" value="Serilog.Sinks.RollingFile.Extension"/>
    <add key="serilog:write-to:SizeRollingFile.pathFormat" value="C:\temp\log.txt"/>
    <add key="serilog:write-to:SizeRollingFile.fileSizeLimitBytes" value="10485760"/>
    <add key="serilog:write-to:SizeRollingFile.retainedFileDurationLimit" value="2.00:00:00"/>
</appSettings>
JSON appsettings.json configuration

To use the file sink with Microsoft.Extensions.Configuration, for example with ASP.NET Core or .NET Core, use the Serilog.Settings.Configuration package. First install that package if you have not already done so:

Install-Package Serilog.Settings.Configuration

Instead of configuring the file directly in code, call ReadFrom.Configuration():

var configuration = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json")
    .Build();

var logger = new LoggerConfiguration()
    .ReadFrom.Configuration(configuration)
    .CreateLogger();

your appsettings.json file should look like this :

{
  "Serilog": {
    "Using": [ "Serilog.Sinks.RollingFile.Extension" ],
    "MinimumLevel": "Debug",
    "WriteTo": [
      {
        "Name": "SizeRollingFile",
        "Args": {
          "pathFormat": "C:\\temp\\log.txt",
          "fileSizeLimitBytes ": 200,
          "retainedFileDurationLimit": "00:00:30"
        }
      }
    ]
  }
}

New Feature

1. Separating output file based on Log Level

Adding new variable in path tamplte to suppoert the log's {Level}, can use it same as {Date} variable


<add key="serilog:write-to:SizeRollingFile.pathFormat" value="C:\temp\log-{Date}-{Level}.txt"/>

2. Writing log in file asynchronously

To enable async, should enable in config file as follow

<add key="serilog:write-to:SizeRollingFile.supportAsync" value="true" />

There are defferent parameter that can update the default value

<add key="serilog:write-to:SizeRollingFile.maxRetries" value="5" /> 
<add key="serilog:write-to:SizeRollingFile.bufferSize" value="9999" /> 
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 was computed.  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 net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  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 Serilog.Sinks.RollingFile.Extension:

Package Downloads
EasyELK

An easy way to send logs to an ELK stack

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Serilog.Sinks.RollingFile.Extension:

Repository Stars
alxnbl/onenote-md-exporter
ConsoleApp to export OneNote notebooks to Markdown formats
Version Downloads Last updated
2.0.2 234,351 10/10/2018
2.0.1-alpha 624 10/10/2018
2.0.0-alpha 637 10/9/2018
1.0.5 92,353 11/10/2016
1.0.5-Beta 1,148 10/31/2016
1.0.5-alpha 945 10/27/2016
1.0.4 2,529 10/13/2016
1.0.3 10,272 2/11/2016
1.0.2 1,385 2/5/2016
1.0.1 1,089 2/5/2016