Kothf.Logging.File
2.10.8
dotnet add package Kothf.Logging.File --version 2.10.8
NuGet\Install-Package Kothf.Logging.File -Version 2.10.8
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="Kothf.Logging.File" Version="2.10.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Kothf.Logging.File" Version="2.10.8" />
<PackageReference Include="Kothf.Logging.File" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Kothf.Logging.File --version 2.10.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Kothf.Logging.File, 2.10.8"
#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.
#:package Kothf.Logging.File@2.10.8
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Kothf.Logging.File&version=2.10.8
#tool nuget:?package=Kothf.Logging.File&version=2.10.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Kothf.Logging.File
A lightweight file logger implementation for the Microsoft.Extensions.Logging framework.
The code is heavily cribbed from the Azure App Service Logging Provider from the ASP.NET team.
The configuration reloading feature was eliminated.
Usage
appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Warning"
},
"FileLog": {
"LogLevel": {
"Default": "Information",
"Microsoft": "None",
"Microsoft.Hosting.Lifetime": "None"
}
}
},
"FileLoggerOptions": {
"LogDirectory": "C:\\Kothf.Logging.File\\logs",
"FileName": "log-"
}
}
Program.cs
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
namespace Kothf.Logging.File.Tests;
internal class Program
{
internal static async Task Main(string[] args)
{
try
{
var builder = Host.CreateEmptyApplicationBuilder(new() { Args = args });
builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: false);
builder.Logging.AddSimpleConsole(options =>
{
options.SingleLine = true;
options.TimestampFormat = "yyyy-MM-dd HH:mm:ss.fff ";
});
// 1. Configure file logger options from configuration file
var fileLoggerOptions = builder.Configuration.GetRequiredSection("FileLoggerOptions");
// 2. Ensure log directory exists
string? logDirectory = fileLoggerOptions.GetValue<string>("LogDirectory");
ArgumentException.ThrowIfNullOrEmpty(logDirectory);
Directory.CreateDirectory(logDirectory!);
// 3. Register file logger options and add file logger
builder.Services.Configure<FileLoggerOptions>(fileLoggerOptions);
builder.Logging.AddFile();
builder.Services
.AddHostedService<TestsWorker>();
var host = builder.Build();
await host.RunAsync();
}
catch (OperationCanceledException)
{
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.ToString());
Environment.ExitCode = 1;
}
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Microsoft.Extensions.Logging (>= 10.0.11)
-
net8.0
- Microsoft.Extensions.Logging (>= 10.0.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.