MJBLogger 1.0.1
dotnet add package MJBLogger --version 1.0.1
NuGet\Install-Package MJBLogger -Version 1.0.1
<PackageReference Include="MJBLogger" Version="1.0.1" />
paket add MJBLogger --version 1.0.1
#r "nuget: MJBLogger, 1.0.1"
// Install MJBLogger as a Cake Addin #addin nuget:?package=MJBLogger&version=1.0.1 // Install MJBLogger as a Cake Tool #tool nuget:?package=MJBLogger&version=1.0.1
Introducing The MJB Class Library
MJBLogger is a configurable, simple-to-use text file logging class library intended to allow you to add logging functionality to your .NET applications without much fuss.
Creating a Simple Application Log
To add logging to your application:
namespace Sample
{
class Program
{
static void Main(string[] args)
{
//Instantiate the log oject
MJBLog Log = new MJBLog();
//Write an introductory message to the log
Log.Banner();
//Write an informational message to the log:
Log.Info(@"Hello World!");
}
}
}
After executing your application, you will find a "logs" folder created in the bin directory. By default, the log files created within are named after the assembly (e.g. "Sample_1.log"). The contents of the log generated by the program above is as follows:
==================================================
Sample -- invoked by MYPC\mikeb -- 07/13/2020 11:54:50.791
==================================================
07/13/2020 11:54:50.799 <Info > [Program.Main] Hello World!
Customizing the Log Format
MJB Logger includes many options to customize log appearance and behavior
MJBLog Log = new MJBLog()
{
//Write log messages to the output window of console applications..
ConsoleEcho = true,
//..but only if the criticality is at least Informational
ConsoleEchoLevel = LogLevel.Info
};
Log.Critical(@"Oh no! A critical error occurred!");
//Save screen space by:
//Using shortened criticality labels:
Log.UseChibiLevelLabels = true;
//...And ommitting the datestamp
Log.IncludeDateStamps = false;
Log.Critical(@"Oops! Another error..");
When this program executes, the log entries are written to the output window as well as the log file (so long as this is a console application). Also, the appearance of the second log entry reflects the properties we changed:
07/13/2020 12:13:35.444 <Critical > [Program.Main] Oh no! A critical error occurred!
12:13:35.457 <Crit > [Program.Main] Oops! Another error..
Object Property Reports
MJBLogger allows you to log a dump a justified list of the names and values of all string, int and bool-type properties of any object using a single statement:
public class Fruit
{
public string Name { get; set; }
public string Type { get; set; }
public int Quantity { get; set; }
}
class Program
{
static void Main(string[] args)
{
MJBLog Log = new MJBLog();
Fruit Orange = new Fruit()
{
Name = nameof(Orange),
Type = @"Citris",
Quantity = 20
};
Log.PropertyReport(Orange);
}
}
In the log file, we find:
07/13/2020 12:20:36.606 <Info > [Program.Main] Sample.Fruit properties:
Name : Orange
Type : Citris
Quantity : 20
Full documentation for the MJBLogger class library can be found at X509Crypto.org
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. |
.NET Core | netcoreapp3.1 is compatible. |
.NET Framework | net472 is compatible. net48 was computed. net481 was computed. |
-
.NETCoreApp 3.1
- Microsoft.Extensions.Caching.Memory (>= 6.0.0)
-
.NETFramework 4.7.2
- Microsoft.Extensions.Caching.Memory (>= 6.0.0)
-
net5.0
- Microsoft.Extensions.Caching.Memory (>= 6.0.0)
-
net6.0
- Microsoft.Extensions.Caching.Memory (>= 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.