Packof7.Australia.Logging 5.0.1

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

// Install Packof7.Australia.Logging as a Cake Tool
#tool nuget:?package=Packof7.Australia.Logging&version=5.0.1

Packof7.Australia.Logging

The Pack of 7 Logging package contains a File Logger for implementing custom log files within any .NET >= 5.0 application. The Package also consists of Packof7.Australia.Logging.Microsoft which implements a custom implementation of logging within the application by logging the current date and time as a prefix before each and every message.

How to (Packof7.Australia.Logging)

Once the package has been added to your application, you can simply use the File Logger by calling the FileLogger constructor with either a FileLoggerConfiguration object as the parameter (Option A), or an Action to configure a new FileLoggerConfiguration object (Option B). These two implementations are used as examples below in regards to instantiating a new FileLogger. In regards to option A, you can either create a new FileLoggerConfiguration object, or you can configure it using Microsoft.Extensions.Options.

Option A (FileLoggerConfiguration config)

In the appsettings.json file, the following can be configured

"FileLoggerName": {
    "FilePath": "c:\\temp\\",
    "FileName": "Test_{UNIQUE}.log",
    "MinLogLevel": "Information",
    "Expiry": 2
}

Which can then be configured within the Startup.cs inside of the ConfigureServices() Method, like so:

services.Configure<LogFileConfiguration>(Configuration.GetSection("FileLoggerName"));

Finally, you can then create the FileLogger within the application simply by using Microsoft.Extensions.Options as follows:

public ClassA(IOptions<LogFileConfiguration> configuraion)
{
    _configuration = configuration.Value;
}

public void SomeMethodInsideClassA()
{
    FileLogger fileLogger = new FileLogger(_configuration);
}

Option B (Action<FileLoggerConfiguration> action)

Another possible way to create a new FileLogger is on-the-fly using an Action to create a new configuration as follows:

FileLogger fileLogger = new FileLogger(config => {
    config.FileName = "NewLog_{UNIQUE}.log";
    config.FilePath = "C:\\Users\\Public\\Documents\\";
    config.MinLogLevel = "Debug";
    config.Expiry = 1;
});

fileLogger.LogInformation("Testing");

How to (Packof7.Australia.Logging.Microsoft)

This sub-package enables custom configuration of Colour Logging within your application. This can be configured easily with the help of the extension methods provided. The Colour logger can be created within either the Startup.cs file or the Program.cs file. The decision is completely up to the developer using the package and has no difference what so ever.

Option A (Program.cs)

Inside of the Program.cs file, the CreateHostBuilder() can configure the Colour logger using the default CreateCustomProvider() function.

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.ConfigureLogging(c => {
                c.ClearProviders();
                c.CreateCustomProvider();
            });
            webBuilder.UseStartup<Startup>();
        });

Take note of the c.CreateCustomProvider(); method. This will create the custom logger with the default settings. To change the default values, simply overwrite the config using the AddCustomProvider() methods as follows:

public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.ConfigureLogging(c => {
                    c.ClearProviders();
                    c.AddCustomProvider(config => {
                        config.LogLevel = LogLevel.Debug;
                        config.Color = ConsoleColor.Blue;
                    }).AddCustomProvider(config => {
                        config.LogLevel = LogLevel.Information;
                        config.Color = ConsoleColor.Green;
                    }).AddCustomProvider(config => {
                        config.LogLevel = LogLevel.Warning;
                        config.Color = ConsoleColor.Yellow;
                    }).AddCustomProvider(config => {
                        config.LogLevel = LogLevel.Error;
                        config.Color = ConsoleColor.Red;
                    }).AddCustomProvider(config => {
                        config.LogLevel = LogLevel.Critical;
                        config.Color = ConsoleColor.DarkMagenta;
                    });
                });
                webBuilder.UseStartup<Startup>();
            });

Option B (Startup.cs)

Option B is to use similar functions within the Startup.cs file's Configure() method as follows, however the default providers should be cleared beforehand. Firstly you will need to inject the ILoggerFactory into the Configure() method as follows:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory factory, ILogger<Startup> logger)
{
    // Implementation
}

Then you can call the following methods to configure the colour logger:

factory.CreateCustomLogger();

or

factory.AddCustomConfiguration(config => {
        config.LogLevel = LogLevel.Debug;
        config.Color = ConsoleColor.Blue;
    }).AddCustomConfiguration(config => {
        config.LogLevel = LogLevel.Information;
        config.Color = ConsoleColor.Green;
    }).AddCustomConfiguration(config => {
        config.LogLevel = LogLevel.Warning;
        config.Color = ConsoleColor.Yellow;
    }).AddCustomConfiguration(config => {
        config.LogLevel = LogLevel.Error;
        config.Color = ConsoleColor.Red;
    }).AddCustomConfiguration(config => {
        config.LogLevel = LogLevel.Critical;
        config.Color = ConsoleColor.DarkMagenta;
    });


                
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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. 
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
5.0.1 1,438 4/8/2021
5.0.0 726 4/8/2021
3.0.1 802 1/14/2021
3.0.0 934 11/14/2020
2.0.0 857 11/4/2020