Gbase.NLog.JsonTarget
1.0.0
See the version list below for details.
dotnet add package Gbase.NLog.JsonTarget --version 1.0.0
NuGet\Install-Package Gbase.NLog.JsonTarget -Version 1.0.0
<PackageReference Include="Gbase.NLog.JsonTarget" Version="1.0.0" />
paket add Gbase.NLog.JsonTarget --version 1.0.0
#r "nuget: Gbase.NLog.JsonTarget, 1.0.0"
// Install Gbase.NLog.JsonTarget as a Cake Addin #addin nuget:?package=Gbase.NLog.JsonTarget&version=1.0.0 // Install Gbase.NLog.JsonTarget as a Cake Tool #tool nuget:?package=Gbase.NLog.JsonTarget&version=1.0.0
Gbase.NLog.JsonTarget
=====================
A NLog target that posts Json to a http endpoint
Dependencies
------------
Currently using ServiceStack.Text for serialization and HttpClient to post asynchronously.
Usage
-----
Add Gbase.NLog.JsonTarget to your solution and update your nlog.config:
Add the assembly to the extensions section
<extensions>
<add assembly="Gbase.NLog.JsonTarget" />
</extensions>
Add the target with a url & fields to post
<targets async="true">
<target name="SampleTarget" xsi:type="JsonPost"
url="http://myrestservice.com/logjson/">
<field name="time" layout="${date:universalTime=True:format=yyyy-MM-ddTHH\:mm\:ss.FFFZ}" />
<field name="msg" layout="${message}" />
<field name="src" layout="${logger}" />
<field name="lvl" layout="${level}" />
<field name="exception" />
<field name="properties"/>
</target>
</targets>
*Field* can be a layout or property of the LogEventInfo class. In this example the exception and properties
of the log event will be sent as objects.
Add a rule to send log events to the target
<rules>
<logger name="*" minlevel="Debug" writeTo="SampleTarget"/>
</rules>
Examples
--------
var log = LogManager.GetLogger("myloggername");
var le = new LogEventInfo();
le.Level = LogLevel.Info;
le.Message = "Hello, Json";
le.Properties["a key"] = "a value";
le.Properties[5] = 10;
log.Log(le);
*produces*
{
"time" : "0001-01-01T05:00:00Z",
"msg" : "Hello, Json",
"lvl" : "Info",
"src" : "myloggername",
"properties" : {
"a key" : "a value",
"5" : 10,
}
}
License
--------
Released under MIT License. Enjoy!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net451 is compatible. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 4.5.1
- NLog (>= 3.1.0)
- ServiceStack.Text (>= 4.0.30)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.