ChrisForte.Microsoft.Extensions.Logging.Files
6.0.0.2
See the version list below for details.
dotnet add package ChrisForte.Microsoft.Extensions.Logging.Files --version 6.0.0.2
NuGet\Install-Package ChrisForte.Microsoft.Extensions.Logging.Files -Version 6.0.0.2
<PackageReference Include="ChrisForte.Microsoft.Extensions.Logging.Files" Version="6.0.0.2" />
paket add ChrisForte.Microsoft.Extensions.Logging.Files --version 6.0.0.2
#r "nuget: ChrisForte.Microsoft.Extensions.Logging.Files, 6.0.0.2"
// Install ChrisForte.Microsoft.Extensions.Logging.Files as a Cake Addin #addin nuget:?package=ChrisForte.Microsoft.Extensions.Logging.Files&version=6.0.0.2 // Install ChrisForte.Microsoft.Extensions.Logging.Files as a Cake Tool #tool nuget:?package=ChrisForte.Microsoft.Extensions.Logging.Files&version=6.0.0.2
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
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. 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. |
-
net5.0
- Microsoft.Extensions.Hosting (>= 5.0.0)
-
net6.0
- Microsoft.Extensions.Hosting (>= 6.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.
Fix for formatters not being implemented in all scenarios.