NReco.Logging.File alternatives and similar packages
Based on the "Logging" category.
Alternatively, view NReco.Logging.File alternatives based on common mentions on social networks and blogs.
-
Serilog
A no-nonsense logging library for the NoSQL era. Combines the best of traditional and structured diagnostic logging in an easy-to-use package. -
StackExchange.Exceptional
Error handler used for the Stack Exchange network -
Logary
Logary is a high performance, multi-target logging, metric, tracing and health-check library for mono and .Net. .Net's answer to DropWizard. Supports many targets, built for micro-services. -
Sentry
.NET SDK for Sentry Open-source error tracking that helps developers monitor and fix crashes in real time.. -
Semantic Logging Application Block (SLAB)
Extends the inbuilt features of System.Diagnostics.Tracing namespace (EventSource class) to log to several sinks including Azure Tables, Databases, files (JSON, XML, text). Supports in-process and out-of-process logging through ETW, and Rx for real-time filtering/aggregating of events. -
Rollbar.NET
Simplifies real-time remote error monitoring while using Rollbar.com. Open-source Rollbar Notifier SDK for any .NET-based technology stack. The SDK that can be used in any application built on the following .NET versions: .NET Core 2.0+, .NET Standard 2.0+, .NET Full Framework 4.5.1+, Mono, Xamarin, and, in general, any implementation of the .NET Standard 2.0+. It simplifies building data payloads based on exception data, tracing data, informational messages, and telemetry data and sends the payloads to the Rollbar API for remote monitoring and analysis of the hosting application's behavior. -
Serilog.Sinks.Notepad
A Serilog sink that writes log events to Notepad as text or JSON -
BugGuardian
BugGuardian: Easily track you exceptions on Azure DevOps and TFS -
Serilog.Sinks.ExcelDnaLogDisplay
A Serilog sink that writes events to Excel-DNA LogDisplay -
ExcelDna.Diagnostics.Serilog
Integrate Excel-DNA Diagnostic Logging with your Serilog logging pipeling within your Excel-DNA add-in -
NLog.Targets.Pushover
NLog.Targets.Pushover is a custom target for NLog enabling you to send logging messages to the Pushover service -
Essential Diagnostics
Extends the inbuilt features of System.Diagnostics namespace to provide flexible logging -
BugSnag
Logs errors. Includes useful diagnostic info like stack trace, session, release, etc. Has a free tier. [Free for OSS][$]
Pixel-Perfect Multi-Platform Applications with C# and XAML
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest. Visit our partner's website for more details.
Do you think we are missing an alternative of NReco.Logging.File or a related project?
README
NReco.Logging.File
Simple and efficient file logger provider for .NET Core (any version) without additional dependencies.
- very similar to standard ConsoleLogger but writes to a file
- can append to existing file or overwrite log file on restart
- supports a 'rolling file' behaviour and can control total log size
- it is possible to change log file name on-the-fly
- suitable for intensive concurrent usage: has internal message queue to avoid threads blocking
How to use
Add NReco.Logging.File package reference and initialize a file logging provider in services.AddLogging
(Startup.cs):
services.AddLogging(loggingBuilder => {
loggingBuilder.AddFile("app.log", append:true);
});
or
services.AddLogging(loggingBuilder => {
var loggingSection = Configuration.GetSection("Logging");
loggingBuilder.AddFile(loggingSection);
});
Example of the configuration section in appsettings.json:
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Error"
},
"File": {
"Path": "app.log",
"Append": "True",
"FileSizeLimitBytes": 0, // use to activate rolling file behaviour
"MaxRollingFiles": 0 // use to specify max number of log files
}
}
Rolling File
This feature is activated with FileLoggerOptions
properties: FileSizeLimitBytes
and MaxRollingFiles
. Lets assume that file logger is configured for "test.log":
- if only
FileSizeLimitBytes
is specified file logger will create "test.log", "test1.log", "test2.log" etc - use
MaxRollingFiles
in addition toFileSizeLimitBytes
to limit number of log files; for example, for value "3" file logger will create "test.log", "test1.log", "test2.log" and again "test.log", "test1.log" (old files will be overwritten).
Change log file name on-the-fly
It is possible to specify a custom log file name formatter with FileLoggerOptions
property FormatLogFileName
. Log file name may change in time - for example, to create a new log file per day:
services.AddLogging(loggingBuilder => {
loggingBuilder.AddFile("app_{0:yyyy}-{0:MM}-{0:dd}.log", fileLoggerOpts => {
fileLoggerOpts.FormatLogFileName = fName => {
return String.Format(fName, DateTime.UtcNow);
};
});
});
Note that this handler is called on every log message 'write'; you may cache the log file name calculation in your handler to avoid any potential overhead in case of high-load logger usage.
Custom log entry formatting
You can specify FileLoggerProvider.FormatLogEntry
handler to customize log entry content. For example, it is possible to write log entry as JSON array:
loggerFactory.AddProvider(new NReco.Logging.File.FileLoggerProvider("logs/app.js", true) {
FormatLogEntry = (msg) => {
var sb = new System.Text.StringBuilder();
StringWriter sw = new StringWriter(sb);
var jsonWriter = new Newtonsoft.Json.JsonTextWriter(sw);
jsonWriter.WriteStartArray();
jsonWriter.WriteValue(DateTime.Now.ToString("o"));
jsonWriter.WriteValue(msg.LogLevel.ToString());
jsonWriter.WriteValue(msg.LogName);
jsonWriter.WriteValue(msg.EventId.Id);
jsonWriter.WriteValue(msg.Message);
jsonWriter.WriteValue(msg.Exception?.ToString());
jsonWriter.WriteEndArray();
return sb.ToString();
}
});
(in case of .NET Core 2 use loggingBuilder.AddProvider
instead of loggerFactory.AddProvider
).
License
Copyright 2017-2020 Vitaliy Fedorchenko and contributors
Distributed under the MIT license
*Note that all licence references and agreements mentioned in the NReco.Logging.File README section above
are relevant to that project's source code only.