The easiest logging library to use to send log messages to syslog, the console, or the file system. It's. REALLY. Easy.
$ dotnet add package SyslogLoggingSimple C# class library for logging to syslog, console, and file, targeted to .NET Core, .NET Standard, and .NET Framework. For a sample app please refer to the included test project.
SyslogLogging is targeted to .NET Core, .NET Standard, and .NET Framework.
First things first - do you need help or have feedback? File an issue here! We'd love to hear from you.
By default, 127.0.0.1:514 is automatically included in the list of servers.
using SyslogLogging;
LoggingModule log = new LoggingModule(); // 127.0.0.1:514 is automatically included
log.Debug("This is a debug message!");
using SyslogLogging;
List<SyslogServer> servers = new List<SyslogServer>
{
new SyslogServer("logginghost.com", 2000),
new SyslogServer("myhost.com", 514)
};
LoggingModule log = new LoggingModule(servers, true); // true to enable console
log.Warn("Look out!");
using SyslogLogging;
LoggingModule log = new LoggingModule("mylogfile.txt");
log.Info("Here's some new information!");
using SyslogLogging;
List<SyslogServer> servers = new List<SyslogServer>
{
new SyslogServer("127.0.0.1", 514)
};
LoggingModule log = new LoggingModule(servers, true); // true to enable console
log.Settings.FileLogging = FileLoggingMode.SingleLogFile;
log.Settings.LogFilename = "mylogfile.txt";
log.Alert("We're going everywhere!");
When using FileLoggingMode.FileWithDate, LoggingModule with append .yyyyMMdd to the supplied filename in LogFilename. When using FileLoggingMode.SingleLogFile, the filename is left untouched.
Tested and works well in Windows in .NET Framework 4.5.2 or later or .NET Core. Tested and works well in Linux and OSX environments, too. Should work well in Mono environments. You may want to use the Mono Ahead-of-time compiler (AOT).
This package has also been tested with PaperTrail. Realistically, any cloud syslog server should work.
If you wish to change the colors used by the library, modify the Settings.Colors property. A variable of type ColorScheme exists for each severity level. To disable colors, set Settings.EnableColors to false.
log.Settings.EnableColors = true;
log.Settings.Colors.Debug = new ColorScheme(ConsoleColor.DarkGray, ConsoleColor.Black);
We'd like to extend a special thank you to those that have helped make this library better, including:
@dev-jan @jisotalo
Please refer to CHANGELOG.md.