My Website: Corpi1.uk
C1Log is a modern, thread-safe, and highly configurable logging library for .NET applications.
It supports asynchronous logging, file rolling (by date and size), minimum log level filtering, syslog-style log levels (with shorthand), and custom log sinks for advanced scenarios.
To use this library, install it via NuGet in your project. You can do this by running the following command in the Package Manager Console:
Latest Version:
NuGet\Install-Package C1.LoggerSpecific Version:
NuGet\Install-Package C1.Logger --Version x.x.xAlternatively, search for "C1Log" in the NuGet Package Manager in Visual Studio and install it from there.
For a full usage guide, please refer to the Docs
Note:
C1Log is fully self-initializing. You do not need to call any initialization method.
If you want to customize configuration (log directory, minimum log level, formatter, etc.), set those properties before your first log call.
Log Levels:
- Emergency (
emerg) - Alert (
alert) - Critical (
crit) - Error (
error) - Warning (
warn) - Notice (
notice) - Informational (
info) - Debug (
debug)
Basic Examples:
Default usage with default settings:
using C1Logger;
C1Log.Info("Application started.");
C1Log.Flush(); // Ensure all logs are writtenCustomizing the log directory, log level and format:
using C1Logger;
C1Log.LogDirectory = @"C:\Logs"; // Specify your log directory
C1Log.MinLogLevel = C1Log.LogLevel.Warning; // Set minimum log level to Warning
C1Log.Formatter = (dt, lvl, msg) => $"[{lvl.ShortHand()}] {dt:HH:mm:ss} - {msg}"; // Custom log message to use shorthand
C1Log.Info("Application started.");
C1Log.Error("An error occurred.");
C1Log.Flush(); // Ensure all logs are writtenFull API Example:
using System;
using C1Logger;
public class MyCustomSink : C1Log.ILogSink {
public C1Log.LogLevel MinLogLevel => C1Log.LogLevel.Notice;
public void Dispose() { }
public Task WriteAsync(string message,
C1Log.LogLevel level, IDictionary<string, object> context = null) {
// Custom sink logic here
return Task.CompletedTask;
}
}
class Program {
static void Main() {
// Configure logger before first log
C1Log.LogDirectory = @"C:\Logs";
C1Log.MinLogLevel = C1Log.LogLevel.Notice;
C1Log.Formatter = (dt, lvl, msg) => $"[{lvl.ShortHand()}] {dt:HH:mm:ss} - {msg}";
C1Log.AddSink(new MyCustomSink());
// Subscribe to logging failures
C1Log.OnLoggingFailure += ex => Console.Error.WriteLine($"Logging failed: {ex}");
// Log messages
C1Log.Info("Informational message.");
C1Log.Warning("Warning message.");
C1Log.Error("Error message.");
C1Log.Exception(new Exception("Test exception"));
C1Log.Flush(); // Ensure all logs are written
}
}If you want to build the project yourself, follow these steps:
- Install Visual Studio (Community Edition is sufficient).
- Select the .NET desktop development workload during installation.
- Clone the repository to your local machine using Git or download it as a ZIP file.
- Open the folder in Visual Studio as a new project.
- Build the project by selecting Build > Build Solution or pressing
Ctrl + Shift + B.- This should install all required dependencies. If not, manually install them via Manage NuGet Packages.
- Once the build completes, you can run it:
- From Visual Studio: Debug > Start Debugging or
F5 - From the built executable in
\bin\Debug\net8.0(orReleasefor release builds).
- From Visual Studio: Debug > Start Debugging or
This project is licensed under the Corpi1 Software License (Based on Mozilla Public License 2.0).
You are free to use, modify, and distribute the software. Businesses and individuals can use it, including in commercial activities. However, you may not sell, repackage, or monetize the software itself.
See the LICENSE file for full terms.