Giter VIP home page Giter VIP logo

ischemm.nlog.jsontarget's Introduction

ISchemm.NLog.JsonTarget

A NLog target that posts Json to a http endpoint. Forked from https://github.com/jakenuts/Gbase.NLog.JsonTarget.

Dependencies

Currently using Newtonsoft.Json for serialization and HttpClient to post asynchronously.

Usage

Add ISchemm.NLog.JsonTarget to your solution and update your nlog.config:

Add the assembly to the extensions section

<extensions>
    <add assembly="ISchemm.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" />                <!--The actual exception object serialized to json-->
      <field name="properties" /> 
      <field name="keyprop" property="a key"/>  <!--A value in the properties bag under key 'a key'-->
      <field name="another" property="5"/>  
    </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.TimeStamp = DateTime.UtcNow;
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,
    },
    "keyprop" : "a key",
    "another" : 10
}

Changes

v1.0.5

  • Initial Release (from Gbase.NLog.JsonTarget v1.0.4)

v2.0.0

  • Add retryIntervals setting (default is 0,60,240,300)
  • Use CancellationToken to cancel tasks when the application closes
  • Remove override of FlushAsync method (which was only waiting for tasks to complete and, in this situation, could take a long time)

v2.0.1

  • Remove README.md and nlog.config.example from nupkg

License

Released under MIT License. Enjoy!

ischemm.nlog.jsontarget's People

Contributors

isaacschemm avatar jakenuts avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.