The Graylog logger is not explicitly only a logger for Graylog. It is actually a network logger, capable to send messages to any network address. This logger becomes a Graylog logger only in combination with logging type GELF.
An example of how to use the network logger together with GELF and how to configure it is shown below.
using Plexdata.LogWriter.Abstraction;
using Plexdata.LogWriter.Definitions;
using Plexdata.LogWriter.Logging;
using Plexdata.LogWriter.Settings;
using System;
namespace Plexdata.LogWriter.Examples
{
class Program
{
static void Main(String[] args)
{
INetworkLoggerSettings settings = new NetworkLoggerSettings()
{
LogLevel = LogLevel.Trace,
LogType = LogType.Gelf,
Host = "http://localhost/logging/gelf",
Port = 42031,
Address = Address.Unknown,
Protocol = Protocol.Web,
ShowKey = false,
ShowTime = true,
Termination = false,
Timeout = 100,
Method = "POST",
Content = "application/json"
};
using (INetworkLogger instance = new NetworkLogger(settings))
{
instance.Write(LogLevel.Trace, "This is a Trace logging entry.");
instance.Write(LogLevel.Debug, "This is a Debug logging entry.");
instance.Write(LogLevel.Verbose, "This is a Verbose logging entry.");
instance.Write(LogLevel.Message, "This is a Message logging entry.");
instance.Write(LogLevel.Warning, "This is a Warning logging entry.");
instance.Write(LogLevel.Error, "This is a Error logging entry.");
instance.Write(LogLevel.Fatal, "This is a Fatal logging entry.");
instance.Write(LogLevel.Critical, "This is a Critical logging entry.");
instance.Write(LogLevel.Disaster, "This is a Disaster logging entry.");
}
}
}
}
The dependency injection of the network logger works pretty much the same way as it works for the console logger. Therefore, an explicit explanation does not really be useful right here.
Finally, a fully qualified configuration example as JSON can be seen here.
{
"Plexdata": {
"LogWriter": {
"Settings": {
"LogLevel": "Trace",
"LogTime": "utc",
"LogType": "gelf",
"ShowKey": false,
"ShowTime": true,
"FullName": false,
"Culture": "en-US",
"Termination": false,
"Host": "http://localhost/logging/gelf",
"Port": 42031,
"Protocol": "web",
"Timeout": 500,
"Method": "POST",
"Content": "application/json"
}
}
}
}