/FluentdClient.Sharp

Fluentd client for C# and VB.NET.

Primary LanguageC#MIT LicenseMIT

FluentdClient.Sharp

Fluentd client for C# and VB.NET that is thin and simple.

Currently, it supports TCP connection only.

AppVeyor NuGet

Install

from NuGet - FluentdClient.Sharp

PM > Install-Package FluentdClient.Sharp

How to use

At first, you must create an instance of FluentdClient, with giving the informations of fluentd server(host and port) and the serializer(messagepack formatted), or the instance of FluentdSetting including those.

Next, you can connect to fluetnd server with calling ConnectAsync method.

Finally, you can send a message to fluentd server to call SendAsync method. (If you don't call ConnectAsync method before, FluetndClient calls it automatically.)

using (var client = new FluentdClient("172.0.0.1", 24224, new MsgPackSerializer()))
{
    await client.ConnectAsync();

    // send a simple message.
    await client.SendAsync("tag.simple", "hello fluentd.");

    // send a structured message.
    await client.SendAsync("tag.structured", new { MachineName = Environment.MachineName });
}

If you use FluentdSetting when you create the instance of FluentdClient, you can set the timeout and how to handle exceptions when sending messages to fluentd server.

var setting = new FluentdSetting("172.0.0.1", 24224, new MessagePackSerializer());

// set timeout(ms)
setting.Timeout = 5000;
// set how to handle exception
setting.ExceptionHandler = new Action<Exception>(ex => Console.WriteLine(ex));

using (var client = new FluentdClient(setting))
{
    // …
}

Serializers

You can choice the serialization libraries, MsgPack-Cli or MessagePack for C#.

MsgPack-Cli is the standard MessagePack library for .NET, that is included in msgpack Github repository.

MessagePack for C# is the extreamly fast MessagePack library for .NET, and faster than other binary / JSON format serializers.

You can get implemented libraries from NuGet.

PM > FluentdClient.Sharp.MsgPack
PM > FluentdClient.Sharp.MessagePack

Both can be injected the custom serialization setting when creating instances.

MsgPackSerializer(implementation of MsgPack-Cli) recieves a instance of SerializationContext. You can see about SerializationContext here.

If you don't give a instance of SerializationContext, SerializationContext.Default is given.

var context = new SerializationContext();

var serializer = new MsgPackSerializer(context);

MessagePackSerializer(implementation of MessagePack for C#) recieves a instance of IMessagePackFormatterResolver. You can see about IMessagePackFormatterResolver here.

If you don't give a instance of IMessagePackFormatterResolver, TypelessContractlessStandardResolver.Instance is given.

MultipleFormatterResolver is used inner actually because it includes PayloadFormatterResolver that resolves the format of Payload(message class) and UnixTimestampFormatterResolver that resolves the format of DateTime and DateTimeOffset as UnixTimestamp.

var serializer = new MessagePackSerializer(StandardResolver.Instance);

Lisence

under MIT Lisence