A .NET client for loggly. Supporting Https, Syslog UDP and encrypted Syslog TCP transports. Install via nuget with
Install-Package loggly-csharp
Note Version 3.5 has completely broken compatibility with prior versions to bring major improvements. Any existing code targeting versions < 3.0 will require modification.
Configuration is done via your app.config. The minimal amount config you require is to specify your customerToken
:
<configuration>
<configSections>
<section name="loggly" type="Loggly.Config.LogglyAppConfig, Loggly.Config"/>
</configSections>
<loggly xmlns="Loggly" customerToken="your token here" />
</configuration>
When you get that working, take the training wheels off and go crazy:
<loggly
xmlns="Loggly"
applicationName="MyAwesomeApp"
customerToken="your token here"
isEnabled="true"
throwExceptions="true">
<transport logTransport="Https" endpointHostname="logs-01.loggly.com" endpointPort="443"/>
<search account="your_loggly_account" username="a_loggly_username" password="myLittleP0ny!"/>
<tags>
<simple>
<tag value="winforms"/>
</simple>
<complex>
<tag type="Loggly.HostnameTag" formatter="host-{0}"/>
<tag type="Loggly.ApplicationNameTag" formatter="application-{0}"/>
<tag type="Loggly.OperatingSystemVersionTag" formatter="os-{0}"/>
<tag type="Loggly.OperatingSystemPlatformTag" formatter="platform-{0}"/>
</complex>
</tags>
</loggly>
This is an optional attribute. If you leave this attribute out but have NewRelic.AppName
in your app.config, then it will pick that value up automatically.
Render your application name as a tag by using the HostnameTag
(keep reading).
Set it to false on your development machine so that no events are sent to loggly.
Three different transports may be specified with the logTransport
attribute in the transport
element.
The transport element is entirely optional and will default to the Https. The available transports are as follows:
The default transport, posting to Loggly on port 443. Note that application and host source group filtering are not supported by HTTP, so you may wish to consider a Syslog transport.
If you specify an applicationName
in the config, the syslog UDP transport will populate the field so it may be filtered in a source group. Host is also automatically populated by the client. Udp messages are sent in plain text.
Uses Syslog over TCP but is not encrypted. Note this needs to be on port 514 for loggly. Port 514 will be selected if not specified.
Transmits using syslog messages via a secure TLS TCP channel so that your logs are encrypted over the wire. Syslog supports JSON formatted messages just like Https. Port 6514 is required for loggly and will be the default if not specified.
simple
tags are string literals added to the app.config. What you see is what you get.
complex
tags inherit from ComplexTag
. They have the formatter
attribute so you may specify your own string.Format
.
The Assembly
attribute is available as an optional parameter so you can roll your own tags too.
Loggly has certain restrictions around characters allowed in tags. This library automatically replaces illegal characters with an underscore.
If you prefer to set configuration programatically, specify the values via the static LogglyConfig.Instance
class at application startup.
Send simple text messages with something like this.
ILogglyClient _loggly = new LogglyClient();
var logEvent = new LogglyEvent();
logEvent.Data.Add("message", "Simple message at {0}", DateTime.Now);
_loggly.Log(logEvent);
Or log an entire object and let the client send it as structured JSON
logEvent.Data.Add("context", new GlimmerWingPony());
_loggly.Log(logEvent);
The Log
method returns Task<LogResponse>
so it is asynchronous by default but can be awaited. Only the Https transport would be worth awaiting as the Syslog transports are fire and forget.
See example project below in conjunction with the loggly docs
The solution has an example project with sample code to demonstrate the client. Before starting, copy the example config into the user config, eg:
C:\loggly-csharp>copy .\source\Loggly.Example\example.loggly.user.config .\source\Loggly.Example\loggly.user.config
And configure the file with your own customer token.
Of course, there is no need to have a config source in your real app, this is just a convenience for this public repository.
- nlog-targets-loggly An NLog target
- Serilog.Sinks.Loggly Serilog sink
- Bug fixes for syslog transports
###v4.5
- Targets framework 4.5
- Log method returns
Task<LogResponse>
for async/await compatibility
###v3.5
- New maintainer neutmute
- Refactored API with new Config assembly
- Syslog UDP and TCP support added
###v2.0 and prior
- Maintained by Karl Seguin