C1.Logger
1.0.2
dotnet add package C1.Logger --version 1.0.2
NuGet\Install-Package C1.Logger -Version 1.0.2
<PackageReference Include="C1.Logger" Version="1.0.2" />
<PackageVersion Include="C1.Logger" Version="1.0.2" />
<PackageReference Include="C1.Logger" />
paket add C1.Logger --version 1.0.2
#r "nuget: C1.Logger, 1.0.2"
#:package C1.Logger@1.0.2
#addin nuget:?package=C1.Logger&version=1.0.2
#tool nuget:?package=C1.Logger&version=1.0.2
C1Logger
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.
Installation
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.Logger
Specific Version:
NuGet\Install-Package C1.Logger --Version x.x.x
Alternatively, search for "C1Log" in the NuGet Package Manager in Visual Studio and install it from there.
Usage
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 written
Customizing 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 written
Full 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
}
}
Building
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
(orRelease
for release builds).
- From Visual Studio: Debug > Start Debugging or
License
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.
Product | Versions 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. |
-
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.
Initial