Appy.Logging.GrayLog 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Appy.Logging.GrayLog --version 1.0.1
NuGet\Install-Package Appy.Logging.GrayLog -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Appy.Logging.GrayLog" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Appy.Logging.GrayLog --version 1.0.1
#r "nuget: Appy.Logging.GrayLog, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Appy.Logging.GrayLog as a Cake Addin
#addin nuget:?package=Appy.Logging.GrayLog&version=1.0.1

// Install Appy.Logging.GrayLog as a Cake Tool
#tool nuget:?package=Appy.Logging.GrayLog&version=1.0.1

Appy.Logging.GrayLog

.NET GrayLog client library written in C#

Features and Limitations

The Appy GrayLog library is a simple library to write logging records to GrayLog using the UDP protocol. The implementation sends messages by GZIP compressing them, and chuncking them if needed, according to the specifications of the Graylog Extended Log Format (GELF).

NuGet package: https://www.nuget.org/packages/Appy.Logging.GrayLog/

Source code and documentation: https://github.com/codetuner/Appy.Logging.GrayLog

GELF specifications: http://docs.graylog.org/en/latest/pages/gelf.html

Sample Usage

A simple "Hello World" logging application can be created as follows:

Create a project and add the NuGet package "Appy.Logging.GrayLog" to your project.

Then use the following code to write a "Hello World !" log message:

using (var logger = new GrayLogUdpClient())
{ 
    logger.Send("Hello World !");
}

This results in the following logging: Sample 1 logging

The Send() method has the following signature:

public void Send(string shortMessage, string fullMessage = null, object data = null)

The data argument can be a string, a dictionary (System.Collections.IDictionary) an enumerable (System.Collections.IEnumerable), or an object of which the properties will be sent.

A more complete example:

using (var logger = new GrayLogUdpClient())
{ 
    logger.Send("Hello", "Welcome John", new { Username = "John", Email = "john@example.com" });
}

Which results in the following logging: Sample 2 logging

There is also a convenience method to send Exception objects:

using (var logger = new GrayLogUdpClient())
{
    try
    {
        // Example of a thrown exception:
        throw new ApplicationException("Something went wrong.");
    }
    catch (Exception ex)
    {
        // Optionally add additional data to the exception's Data collection:
        ex.Data.Add("context", "Attempt to send an email.");
        ex.Data.Add("level", SyslogLevel.Error);
                            
        // Log the exception:
        logger.Send(ex);
    }
}

Which results in the following logging: Sample 3 logging

These samples assume you have configured your GrayLog connection data into the App.config or Web.config. You need at least following AppSetting keys:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="GrayLogFacility" value="HelloWorldSample"/>
    <add key="GrayLogHost" value="localhost"/>
  </appSettings>
</configuration>

The GrayLogFacility setting specifies the facility argument to set for all messages. The GrayLogHost is the server name of your GrayLog instance. You can also specify the GrayLogUdpPort setting if you want to override the default port number 12201.

Additionally, you can set a compression treshold with the AppSetting key GrayLogCompressionTreshold. By default this value is 0 and means compression is always enabled. Setting this value to i.e. 500 would mean to apply compression only when message body is more than 500 bytes. A value of -1 disables compression completely.

For further usage details and manual, check the project's WIKI page.

Product 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. 
.NET Core netcoreapp2.0 is compatible.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.0.3 29,852 10/17/2017
1.0.2 900 10/17/2017
1.0.1 1,016 10/16/2017