LoggerLibrary_CA 1.0.0

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

LoggerLibrary

A flexible C# logging library designed to provide detailed and configurable logging for .NET applications. This library supports multiple log levels, log rotation based on file size, fallback logging, and XML documentation for IntelliSense support.


Features

  • Multiple log levels: Debug, Info, Warning, Error, and Fatal
  • Configurable via App.config
  • Log rotation based on max file size
  • Thread-safe using Mutex
  • Fallback emergency log file for critical logging failures
  • XML documentation for IntelliSense
  • Easy integration into other projects or distribution as a NuGet package

Getting Started

1. Installation

Add the compiled LoggerLibrary.dll to your project references.

Alternatively, package it into a NuGet package (instructions not included here).

2. Configuration

Add the following settings to your App.config or Web.config:

<appSettings>
  <add key="EnableLog" value="true"/>
  <add key="LogFilePath" value="C:\Logs\MyApp.log"/>
  <add key="LogLevelThreshold" value="Info"/>
  <add key="CurrentLogFilePath" value="C:\Logs\MyApp.log"/>
</appSettings>

Note:

  • LogFilePath and CurrentLogFilePath are optional.
  • If not specified, logs will be created in the default project directory.
  • CurrentLogFilePath is automatically managed by the logger for log rotation continuity.
  • LogLevelThreshold determines the minimum severity of messages to be logged. Messages below this level will be ignored.

3. Usage

Debug Log
Logger.DebugLog("Debugging user authentication flow.");
Info Log
Logger.InfoLog("Application started successfully.");
Warning Log
Logger.WarningLog("Low disk space warning", "Only 500MB left on drive C:");
Error Log with Exception
try
{
    // Some code that might throw
}
catch (Exception ex)
{
    Logger.ErrorLog(ex, "An error occurred during processing.");
}
Fatal Error Log
try
{
    // Some critical code
}
catch (Exception ex)
{
    Logger.FatalLog(ex, "Critical system failure occurred!");
}

Log Rotation

The logger automatically creates a new file once the size exceeds 2MB (as per current setting).
Rotated files will be named like:

MyApp_Part1.log  
MyApp_Part2.log  
...

The CurrentLogFilePath key is used internally to continue writing to the correct file after restart.


Emergency Fallback Logging

If the logger is unable to write to the primary log file (e.g., file is locked, permission issue), the error is written to a persistent fallback log located at:

{BaseDirectory}\EmergencyLogs\emergency_log.log    (where your executable resides)

This ensures critical errors are never silently lost.


Documentation & IntelliSense

The library includes full XML documentation:

  • Method summaries
  • Parameter descriptions
  • Usage examples using <code> tags

To enable IntelliSense in other projects:

  • Distribute the .xml documentation file alongside the DLL.

Contributions & Enhancements

Suggestions and improvements are welcome! Possible enhancements include:

  • Async logging
  • Logging to other targets (e.g., database, remote APIs)
  • Customizable log formatting
  • User-defined log rotation size

License

MIT License. Use freely with attribution.


Author

Created by Central Automation - OIG

Product Compatible and additional computed target framework versions.
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has 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.0.0 185 4/10/2025