Packof7.Australia.Logging 5.0.1

Pack of 7 Australia - Logging

Install-Package Packof7.Australia.Logging -Version 5.0.1
dotnet add package Packof7.Australia.Logging --version 5.0.1
<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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Packof7.Australia.Logging, 5.0.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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;
    });


                

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;
    });


                

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
5.0.1 38 4/8/2021
5.0.0 38 4/8/2021
3.0.1 97 1/14/2021
3.0.0 205 11/14/2020
2.0.0 154 11/4/2020