K.Bag.Log4Net.Extension 0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package K.Bag.Log4Net.Extension --version 0.0.1
                    
NuGet\Install-Package K.Bag.Log4Net.Extension -Version 0.0.1
                    
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="K.Bag.Log4Net.Extension" Version="0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="K.Bag.Log4Net.Extension" Version="0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="K.Bag.Log4Net.Extension" />
                    
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 K.Bag.Log4Net.Extension --version 0.0.1
                    
#r "nuget: K.Bag.Log4Net.Extension, 0.0.1"
                    
#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 K.Bag.Log4Net.Extension@0.0.1
                    
#: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=K.Bag.Log4Net.Extension&version=0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=K.Bag.Log4Net.Extension&version=0.0.1
                    
Install as a Cake Tool

K.Bag.Log4Net.Extension

A powerful and flexible logging extension library built on top of log4net, providing enhanced logging capabilities with customizable formatters, writers, and configurations.

📦 Installation

Install via NuGet Package Manager:

<PackageReference Include="K.Bag.Log4Net.Extension" Version="1.0.0" />

Or via Package Manager Console:

Install-Package K.Bag.Log4Net.Extension

Or via .NET CLI:

dotnet add package K.Bag.Log4Net.Extension

💡 Basic Usage

1. Quick Setup

The easiest way to get started with logging:

using K.Bag.Log4Net.Extension;
using K.Bag.Log4Net.Extension.Configuration;

// Configure the logger once in your application startup
var config = new KlypzLoggerConfiguration();
config.SetFileFormatter(LoggerFileFormatterDefault.CsvPattern);
config.SetConsoleWriter(LoggerWriterConsoleDefault.Modern);

// Set up file logging (optional - omit the path to log only to console)
LoggerManager.ConfigureDefault(config, @"C:\logs\application.log");

// Use the logger in your classes
IKlypzCustomLogger logger = LoggerManager.GetLoggerDefault(typeof(MyClass));
logger.AddInformation("Application started successfully");

2. Advanced Configuration

Configure different logging levels and options:

var config = new KlypzLoggerConfiguration()
{
    DebugEnable = LevelTypeEnable.OnlyConsole, // Debug only shown in console, not file
    InfoEnable = LevelTypeEnable.Both,         // Info shown in both console and file
    WarnEnable = LevelTypeEnable.Both,
    ErrorEnable = LevelTypeEnable.Both,
    FatalEnable = LevelTypeEnable.Both,
    IgnoresException = false,                  // Log exception details
    MaximumFileSize = "10MB",                  // Rotate log files at 10MB
    MaxSizeRollBackups = 5                     // Keep up to 5 rotated log files
};

config.SetFileFormatter(LoggerFileFormatterDefault.TabPattern);
config.SetConsoleWriter(LoggerWriterConsoleDefault.ModernClean);

LoggerManager.ConfigureDefault(config, @"C:\logs\application.log");

3. Different Console Writers

Choose from three built-in console writers:

// Old school style (similar to Situator)
config.SetConsoleWriter(LoggerWriterConsoleDefault.OldSchool);

// Modern formatted output
config.SetConsoleWriter(LoggerWriterConsoleDefault.Modern);

// Clean modern output
config.SetConsoleWriter(LoggerWriterConsoleDefault.ModernClean);

4. Different File Formatters

Choose from three built-in file formatters:

// CSV-style formatting
config.SetFileFormatter(LoggerFileFormatterDefault.CsvPattern);

// Tab-separated formatting  
config.SetFileFormatter(LoggerFileFormatterDefault.TabPattern);

// Traditional .log formatting
config.SetFileFormatter(LoggerFileFormatterDefault.OldSchoolPattern);

5. Using the Logger

Add different types of log messages:

IKlypzCustomLogger logger = LoggerManager.GetLoggerDefault(typeof(MyClass));

// Different log levels
logger.AddDebug("Debugging information");
logger.AddInformation("General information");
logger.AddWarning("Warning message");
logger.AddError("Error occurred");
logger.AddFatal("Fatal error");

// With exception details
try
{
    // Something that throws an exception
}
catch(Exception ex)
{
    logger.AddError("An error occurred processing data", ex);
    logger.AddWarning("Recovering from error", ex);
}

6. Named Loggers

Create multiple loggers with different names for different purposes:

IKlypzCustomLogger dataAccessLogger = LoggerManager.GetLoggerDefault("Data Access");
IKlypzCustomLogger businessLogicLogger = LoggerManager.GetLoggerDefault("Business Logic");

dataAccessLogger.AddDebug("Executing query took 250ms");
businessLogicLogger.AddInformation("User authentication successful");

7. Custom File Formatting

Define custom columns for your log files:

var config = new KlypzLoggerConfiguration();

// Define custom column layout
var columns = new[]
{
    ColumnLog.DateTime,
    ColumnLog.Level,
    ColumnLog.Name,
    ColumnLog.Message,
    ColumnLog.ExceptionMessage
};

config.SetFileFormatter(LoggerFileFormatterDefault.CsvPattern);
config.SetColumnsFormatter(columns);

LoggerManager.ConfigureDefault(config, @"C:\logs\application.log");

⚙️ Configuration Options

Option Type Default Description
DebugEnable LevelTypeEnable Both Control where DEBUG level messages appear
InfoEnable LevelTypeEnable Both Control where INFO level messages appear
WarnEnable LevelTypeEnable Both Control where WARN level messages appear
ErrorEnable LevelTypeEnable Both Control where ERROR level messages appear
FatalEnable LevelTypeEnable Both Control where FATAL level messages appear
IgnoresException bool false Whether to include exception details
MaximumFileSize string 1MB Size when to rotate log files
MaxSizeRollBackups int 5 Number of rotated files to keep

Available LevelTypeEnable values:

  • OnlyFile - Messages appear only in file
  • OnlyConsole - Messages appear only in console
  • Both - Messages appear in both file and console

🔧 Supported Column Types

When configuring file formatters, you can use these column types:

  • ColumnLog.Name - Class or grouping name
  • ColumnLog.FullName - Full class name (namespace + class)
  • ColumnLog.DateTime - Timestamp of log entry
  • ColumnLog.Level - Log level (DEBUG, INFO, WARN, ERROR, FATAL)
  • ColumnLog.Message - Log message
  • ColumnLog.FullMessage - Full message including line breaks
  • ColumnLog.ExceptionMessage - Exception message if provided
  • ColumnLog.ExceptionStackTrace - Exception stack trace if provided
  • ColumnLog.Thread - Thread ID where log occurred

🛠️ Logger Methods

Method Description
AddDebug(string message) Log a debug message
AddDebug(string message, Exception e) Log a debug message with exception details
AddInformation(string message) Log an info message
AddWarning(string message) Log a warning message
AddWarning(string message, Exception e) Log a warning message with exception details
AddError(string message) Log an error message
AddError(string message, Exception e) Log an error message with exception details
AddFatal(string message) Log a fatal message
AddFatal(string message, Exception e) Log a fatal message with exception details

✅ Best Practices

  1. Initialize Once: Configure the logger manager only once during application startup
  2. Use Named Loggers: For different components of your application
  3. Keep Debug Off in Production: Set DebugEnable = LevelTypeEnable.OnlyConsole or disable for production
  4. Manage File Sizes: Use appropriate MaximumFileSize and MaxSizeRollBackups settings
  5. Include Exceptions: Always include exception details when logging errors

📋 Dependencies

This package depends on:

  • log4net

📄 License

See the LICENSE file for licensing information.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 63 2/10/2026
0.0.1 75 2/2/2026