Git Product home page Git Product logo

loggingmodule's Introduction

SyslogLogging

NuGet Version NuGet

Simple 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.

Help or Feedback

First things first - do you need help or have feedback? File an issue here! We'd love to hear from you.

New in v2.0.1

  • Breaking changes including new constructors and minor API changes
  • Support for multiple syslog servers
  • Simplified class definitions

It's Really Easy... I Mean, REALLY Easy

By default, 127.0.0.1:514 is automatically included in the list of servers.

Single Syslog Server

using SyslogLogging;

LoggingModule log = new LoggingModule(); // 127.0.0.1:514 is automatically included
log.Debug("This is a debug message!");

Multiple Syslog Servers and Console

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!");

Logging to File

using SyslogLogging;

LoggingModule log = new LoggingModule("mylogfile.txt");
log.Info("Here's some new information!");

Logging EVERYWHERE

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.

Supported Environments

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.

Changing Console Message Color

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);

Special Thanks

We'd like to extend a special thank you to those that have helped make this library better, including:

@dev-jan @jisotalo

Version History

Please refer to CHANGELOG.md.

loggingmodule's People

Contributors

dev-jan avatar jchristn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

loggingmodule's Issues

Seems to be sending the data twice.

I have this code to listen for syslog traffic
` Private Sub ListenForSyslogs()

    Dim ipeRemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
    Dim udpcUDPClient As New UdpClient(514)
    Dim sDataRecieve As String
    Dim bBytesRecieved() As Byte
    Dim sFromIP As String

    Try
        While True
            bBytesRecieved = udpcUDPClient.Receive(ipeRemoteIpEndPoint)
            sDataRecieve = Encoding.ASCII.GetString(bBytesRecieved)
            sFromIP = ipeRemoteIpEndPoint.Address.ToString

            FillLog(sDataRecieve, sFromIP)

            Console.WriteLine(sDataRecieve)
            sDataRecieve = ""
        End While
    Catch e As Exception
        ' just ignore for now
    End Try
End Sub`

When, from another program I call syslog.info("Middleman checked NETSERV-STN1")
the output from that code is
127.0.0.1,19/05/2021 11:51:11[UNKNOWN]2021-05-19 10:51:11 NETSERV-STN1 4 Info Middleman checked NETSERV-STN1 127.0.0.1,19/05/2021 11:51:11[UNKNOWN]2021-05-19 10:51:11 NETSERV-STN1 4 Info Middleman checked NETSERV-STN1

Possibility to disable UDP logging

Hi again! Thank you for the previous fix, it helped a lot.

Could it be possible to add a property like UdpEnable? It could of course be true as default, but then it would be also possible to easily disable sending data to system log?

So if I have a situation I want to log only to console and file, it could be possible.

Thanks!

Colors in syslog / journalctl ?

Hi,

despite the enabling of colors (using Settings.EnableColors = true) the text in syslog and journalctl still appear gray.
I probably have missed something, but what? Also some other texts from other applications appear in color.

Thanks.

Setting process name?

Hi, is there a way to set the process name? I use dotnet runtime, and it appears as dotnet in syslog (which makes perfectly sense). An option to change the process name could be great.

.NET 4.5.1 support

Hi!

I tried your project and it seems quite useful and simple logger, great! I'm working with a system using .NET Framework 4.5.1 and updating is not possible at the moment. Do you think you could change the dependency to that one?

I cloned and built using 4.5.1 and seems to work fine for at least me! If it's not possible, it's okay. I'm just building it myself then.

Ps. Do you think it would be possible to add virtual keyword to different methods. like Log method? That would allow users to override methods to add some fancy stuff.

Regards
Jussi

Date/time of the logs is not the local one but ever UTC universal

Whatever the date/time of the server/computer used to run a soft whit the SyslogLogging module, the module used UTC universal time.
The time in the logs is a crucial part to understand what happens, especially in a complex system with other softwares, so that issue render the logs generated really hard to analyze.
That could be a good idea to add a parameter to allow to configure if the date should be UTC or not, universal or not.
The only solution for the time being is to does not put {ts} in the format and manually add the date in the message, but the severity come before and it's not nice to see :
Info 2024-08-06 10:05:26.976 : Software starting

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.