RLoggerLib 2.0.0
dotnet add package RLoggerLib --version 2.0.0
NuGet\Install-Package RLoggerLib -Version 2.0.0
<PackageReference Include="RLoggerLib" Version="2.0.0" />
<PackageVersion Include="RLoggerLib" Version="2.0.0" />
<PackageReference Include="RLoggerLib" />
paket add RLoggerLib --version 2.0.0
#r "nuget: RLoggerLib, 2.0.0"
#:package RLoggerLib@2.0.0
#addin nuget:?package=RLoggerLib&version=2.0.0
#tool nuget:?package=RLoggerLib&version=2.0.0
RLoggerLib
[04:03:14] Info: Program[MLog] - Test
[04:03:14] Warning: Program[MLog] - Test
[04:03:14] Error: Program[MLog] - Test
[04:03:14] Critical: Program[MLog] - Test
RLoggerLib is a library that performs logging operations with minimal latency without blocking the main thread. It is designed to be thread-safe, and you can add your own logging targets.
Features
- Minimal latency logging
- Thread-safe
- Customizable logging targets
If you need to know how many days a log is repeated in the same day, you need to save it to SQLite Database. The default logging threshold is Warning and above.
Installation
.NET Framework
For installation on .NET Framework, you need to install the Stub.System.Data.SQLite.Core.NetFramework NuGet package.
.NET Core / .NET 8
For .NET Core and .NET 8, no additional packages are required as the library brings its dependencies internally.
Configuration
All classes with the Options suffix provide certain settings in the creation of the logger.
The MailLoggingTargetOptions doesn't have default instance. Make sure use properly initialized options.
Usage
Windows Forms Application
Program.cs
// Entry point of the application
[STAThread]
static void Main()
{
// Register the main thread
RLogger.RegisterMainThread();
// Create empty logger
RLogger.Create();
// Late binding of logging targets
RLogger.Instance.AddDebugLogging();
RLogger.Instance.LogInfo("Application is starting");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
RLogger.Instance.LogInfo("Application is closing");
}
Form1.cs
public partial class Form1 : Form
{
private readonly IRLogger _logger = RLogger.Instance;
public Form1()
{
InitializeComponent();
_logger.LogDebug("Form1 is initialized", "ExampleSource");
_logger.AddTextFileLogging(new TextFileLoggingTargetOptions()
{
FileNamingConvention = LogFileNamingConvention.CustomDate,
CustomName = "WindowsFormsApp",
DateFormat = "yyyy-MM-dd",
});
_logger.LogTrace("Text file logging is added", "ExampleSource", "B2");
}
private void button1_Click(object sender, EventArgs e)
{
_logger.LogInfo("Button1 is clicked");
}
}
ASP.NET Core Application
Program.cs
var builder = WebApplication.CreateBuilder(args);
// Register the main thread
RLogger.RegisterMainThread();
// Create logger with adding some logging targets
RLogger.Create((logger) =>
{
logger.AddDebugLogging()
.AddConsoleLogging()
.AddTextFileLogging(TextFileLoggingTargetOptions.Default)
.AddMailLogging(new MailLoggingTargetOptions()
{
MinRequiredSeverity = LogType.Critical, //Default is LogType.Error
MailServer = "smtp.gmail.com", // Example mail server
MailPort = 587, // google mail port
MailTo = new string[] { "RECEIVER1 ADDRESS", "RECEIVER2 ADDRESS" },
MailUser = "YOUR MAIL ADDRESS",
MailPassword = "YOUR MAIL PASSWORD",
})
// For Windows Event Logging, you need to run the application as an administrator on Windows.
.AddWindowsEventLogging(WindowsEventLoggingTargetOptions.Default);
});
// Add logging to the DI container as a singleton service
builder.Services.AddSingleton<IRLogger, RLogger>((sp) => RLogger.Instance);
WeatherForecastController.cs
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private readonly IRLogger _rlogger;
public WeatherForecastController(IRLogger rlogger)
{
_rlogger = rlogger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
_rlogger.LogInfo("GetWeatherForecast is called");
return //Result
}
}
Custom Logging Target Example
ConsoleApp/Program.cs
// Entry point of the application
static void Main(string[] args)
{
// Register the main thread
RLogger.RegisterMainThread();
// Create logger with adding some logging targets
RLogger.Create((logger) =>
{
// Add debug, console and custom logging targets
logger.AddDebugLogging()
.AddConsoleLogging(LogType.Debug)
.AddCustomLoggingTarget(new DemoLoggingTarget());
});
RLogger.Instance.LogInfo("Application is running...", "ConsoleApp", "1");
try
{
// Do some work
RLogger.Instance.LogTrace("Job Starting...");
MLog(RLogger.Instance);
RLogger.Instance.LogTrace("Job Completed.");
}
catch (Exception ex)
{
RLogger.Instance.LogError("Job Failed. Ex:" + ex.Message);
}
RLogger.Instance.LogInfo("Application is exited.", "ConsoleApp", "0");
}
// Example of a implement custom logging target
public class DemoLoggingTarget : ILoggingTarget
{
public void Log(LogEntity logEntity)
{
Console.WriteLine("DEMO");
}
}
Calling RegisterMainThread() and Create(any) once is enough. Afterwards, you can access the created logger from anywhere in the Project using RLogger.Instance.
RegisterMainThread() must be called only once in the main thread, otherwise it will throw an error.
Dependencies
System.Data.SQLiteSystem.Diagnostics.EventLog
Contributing
Contributions are welcome! After forking the project and making adjustments and improvements, please complete your documentation and tests and create a pull request.
Project Status
Active Development
License
This project is licensed under the AGPL-3.0 License.
| Product | Versions 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Data.SQLite (>= 1.0.118)
- System.Diagnostics.EventLog (>= 8.0.0)
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 |
|---|---|---|
| 2.0.0 | 206 | 10/7/2024 |