LoggerLibrary_CA 1.0.0
dotnet add package LoggerLibrary_CA --version 1.0.0
NuGet\Install-Package LoggerLibrary_CA -Version 1.0.0
<PackageReference Include="LoggerLibrary_CA" Version="1.0.0" />
<PackageVersion Include="LoggerLibrary_CA" Version="1.0.0" />
<PackageReference Include="LoggerLibrary_CA" />
paket add LoggerLibrary_CA --version 1.0.0
#r "nuget: LoggerLibrary_CA, 1.0.0"
#:package LoggerLibrary_CA@1.0.0
#addin nuget:?package=LoggerLibrary_CA&version=1.0.0
#tool nuget:?package=LoggerLibrary_CA&version=1.0.0
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
, andFatal
- 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
andCurrentLogFilePath
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 | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net48 is compatible. net481 was computed. |
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 |