CodeWithSaar.Extensions.Logging.File 1.0.0-beta1

This is a prerelease version of CodeWithSaar.Extensions.Logging.File.
There is a newer version of this package available.
See the version list below for details.
dotnet add package CodeWithSaar.Extensions.Logging.File --version 1.0.0-beta1
NuGet\Install-Package CodeWithSaar.Extensions.Logging.File -Version 1.0.0-beta1
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="CodeWithSaar.Extensions.Logging.File" Version="1.0.0-beta1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CodeWithSaar.Extensions.Logging.File --version 1.0.0-beta1
#r "nuget: CodeWithSaar.Extensions.Logging.File, 1.0.0-beta1"
#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 CodeWithSaar.Extensions.Logging.File as a Cake Addin
#addin nuget:?package=CodeWithSaar.Extensions.Logging.File&version=1.0.0-beta1&prerelease

// Install CodeWithSaar.Extensions.Logging.File as a Cake Tool
#tool nuget:?package=CodeWithSaar.Extensions.Logging.File&version=1.0.0-beta1&prerelease

CodeWithSaar.Extensions.Logging.File

A file logger provider implementation for Microsoft.Extensions.Logging. At this moment, this package is very easy to use in debugging environment.

Refer to the Known-limitations before you use this in production.

Getting Started

  • Add NuGet Package:

    dotnet add package CodeWithSaar.Extensions.Logging.File
    
  • In ASP.NET Core project, enable the logging provider:

    ...
    // Add services to the container.
    builder.Services.AddLogging(loggingBuilder =>{
        loggingBuilder.AddFile();
    });
    ...
    

    Check out the example project.

  • Run the application and see the log output to output.log.

Customization

Set a different file name

There are generally 2 ways to set log configurations.

  • By code:

    builder.Services.AddLogging(loggingBuilder =>
    {
        loggingBuilder.AddFile(opt => opt.OutputFilePath = "newfilename.log");
    });
    
  • By configuration file (Typically, appsettings.json):

    {
        // General logging
        "Logging": {
            "LogLevel": {
                "Default": "Debug"
            },
            // File provider overwrites
            "FileProvider":
            {
                // Output to output.v2.log file
                "OutputFilePath": "output.v2.log",
                // Specify a different logging level
                "LogLevel":{
                    "Default": "Information"
                }
            }
        }
    }
    

Set different logging levels

Logging levels could be set in through appsettings.json / appsettings.Development.json or whatever the configuration providers in your project.

It would take the default settings like this:

    {
        // Logging Information or above to file
        "Logging": {
            "LogLevel": {
                "Default": "Debug"
            }
        }
    }

Or it could be set to it's own:

{
    // Default logging level of Debug
    "Logging": {
        "LogLevel": {
            "Default": "Debug"
        },
        "FileProvider":
        {
            // Output to output.v2.log file
            "OutputFilePath": "output.v2.log",
            // Specify a different logging level of Information for logs output to the file.
            "LogLevel":{
                "Default": "Information"
            }
        }
    }
}

Known limitations

  • Scope is not supported yet;
  • There might be concurrency issues;
  • File writing performance is not optimized;
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 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

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
1.0.0 650 5/9/2022
1.0.0-beta6 216 5/2/2022
1.0.0-beta5 209 4/19/2022
1.0.0-beta4 181 4/12/2022
1.0.0-beta2 158 4/12/2022
1.0.0-beta1 174 4/12/2022