AbLibs.AbLogger 1.1.0

dotnet add package AbLibs.AbLogger --version 1.1.0
                    
NuGet\Install-Package AbLibs.AbLogger -Version 1.1.0
                    
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="AbLibs.AbLogger" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AbLibs.AbLogger" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="AbLibs.AbLogger" />
                    
Project 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 AbLibs.AbLogger --version 1.1.0
                    
#r "nuget: AbLibs.AbLogger, 1.1.0"
                    
#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 AbLibs.AbLogger@1.1.0
                    
#: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=AbLibs.AbLogger&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=AbLibs.AbLogger&version=1.1.0
                    
Install as a Cake Tool

AbLogger

A quick and dirty logging library for when you don't need anything more than the ability to write to the console and/or a file in a quick and dirty way.

If consistency checking, thread safety and error handling sounds like things you don't need to care about, then AbLogger is exactly right level for you.

Disclaimer: This is a TOY-LEVEL library and should absolutely, in no way, ever, EVER, be used for anything you might ever put in the same room as a the word "productionized".

Instructions

Import abLogger:

using abLogger;

Create a new log manager:

AbLogger logger = new AbLogger();

So far there are no actual log handlers, so calling the log methods won't do anything. So now add log handlers as required.

Adding Log Handlers

Console logger
AddConsoleLogger(LogLevel level)

Adds a log handler that will write any messages meeting the given threshold level to the console. For example, to add a console logger that only writes WARN and ERROR items:

logger.AddConsoleLogger(LogLevel.WARN);

Note: if a console logger has already been added, this method will instead update the existing one with the given log level.

File logger
AddFileLogger(LogLevel level, string filename, FileInitMode fileMode)

Adds a log handler that will write any messages meeting the given threshold to the given file.

FileInitMode has one of two values:

  • Replace: If the file already exists, delete it and start fresh
  • Append: If the file already exists, leave it in place and add log messages to the end

This method can also be called as:

AddFileLogger(LogLevel level, string filename)

which will default the FileInitMode to Append.

or as :

AddFileLogger(LogLevel level)

which will create a random temporary file and use that.

In all three, the filename is the return value of the method call.

If a FileLogger with the given method exists then it will instead be updated with the given log level.

Writing Logs

The AbLogger class has four methods for writing log entries at different log levels:

Debug(String tag, string text);
Info(string tag, string text);
Warn(string tag, string text);
Error(string tag, string text, Exception? ex);

Where:

  • tag is a short string representing a source, event ID, feature, etc
  • text is the main log message
  • ex is an exception which can optionally be included with the Error call

When called, these four methods will write the message using all log handlers with an appropriate log level threshold.

Full example

AbLogger logger = new AbLogger();
// Only put important stuff on the console
logger.AddConsoleLogger(LogLevel.WARN); 
// Write everything to a temp file (and keep the filename so we know where it went)
string fullLog = logger.AddFileLogger(LogLevel.DEBUG);
// Also write errors to a separate file for reporting
logger.AddFileLogger(LogLevel.DEBUG, "./errors.log", FileInitMode.APPEND);

logger.Debug("Sample", "This message will only go to the big log file");
logger.Warn("Sample", "This item will go to the console and the big log file");
logger.Error("Sample", "This message will only go to all three", new Exception("This exception will be recorded too");
Product 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 was computed.  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.
  • net8.0

    • No dependencies.

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.1.0 163 5/6/2025
1.0.0 147 5/6/2025

Updated version to streamline the interface a bit