ChrisForte.Microsoft.Extensions.Logging.Files 8.0.1

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

// Install ChrisForte.Microsoft.Extensions.Logging.Files as a Cake Tool
#tool nuget:?package=ChrisForte.Microsoft.Extensions.Logging.Files&version=8.0.1                

Microsoft.Extensions.Logging.Files

File logger provider for Microsoft.Extensions.Logging that allows logging to local files in different formats.

Usage

In the IHostBuilder chained configuration methods, use .AddFile<IFileLoggerBaseFormatter>(configuration, formatter) under IHostBuilder.ConfigureLogging().

IHost host = Host.CreateDefaultBuilder(args)
    .ConfigureLogging((hostBuilderContext, logging) =>
    {
        logging.ClearProviders();
        logging.AddFile<BasicFormatter>(
                        configuration =>
                        {
                            configuration.Directory = @"C:\Logs";
                            configuration.UseRollingFiles = true;
                            configuration.RollingFileTimestampFormat = @"yyyy-MM-dd";
                            configuration.FileExtension = @"log";
                            configuration.FileNamePrefix = @"MyLogFile";
                            configuration.MinimumLogLevel = LogLevel.Debug;
                        },
                        formatter =>
                        {
                            formatter.CaptureScopes = true;
                            formatter.UseUtcTimestamp = true;
                            formatter.IncludePID = true;
                            formatter.IncludeUser = true;
                        })
               .AddFile<CMTraceFormatter>(configuration => { })
               .AddFile<JSONFormatter>(configuration => { });
    })
    .Build();

Use the configuration delegate action to configure the base log file options, and the formatter delegate action to configure automatic formatting and filtering used by the ILogger instance.

Messages are processed and written immediately, and use a message processor and message queue to write to the underlying FileStream.

Extensions

To create your own file logger format, create a class that implements the FileLoggerBaseFormatter class, and override the Write() method defined in IFileLoggerBaseFormatter. Pass that new class as a type parameter in .AddFile<T>()

public abstract void Write<TState>(in LogEntry<TState> logEntry, IExternalScopeProvider scopeProvider, TextWriter textWriter);

Download

NuGet version (ChrisForte.Microsoft.Extensions.Logging.Files)

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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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

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
8.0.1 132 10/24/2024
8.0.0 321 4/1/2024
7.0.1 331 8/19/2023
7.0.0 470 12/1/2022
6.0.1 569 4/29/2022
6.0.0.2 450 4/28/2022
6.0.0.1 458 4/28/2022
6.0.0 476 4/28/2022 6.0.0 is deprecated because it has critical bugs.

- Update packages