Coder Social home page Coder Social logo

nlog.targets.redisjson's Introduction

NLog.Targets.RedisJson

This project is an NLog target for Redis server.

What it does

Write the logged message as a JSON value with, optionally, a TTL (time-to-live).

Example (With Docker)

Install the NuGet library

Launch the pre-made compose redis-stack docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latest

If you want a password-protected Redis stack docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 -e REDIS_ARGS="--requirepass mystrongpassword" redis/redis-stack:latest

Configure the nlog.config (or the appsettings.json), add the assembly

    <extensions>
        <add assembly="NLog.Targets.Redis" />
    </extensions>

With JsonLayout

JsonLayout is a NLog layout, you can find additional info on doc page and on wiki

<target xsi:type="RedisJson" name="redisjson" host="127.0.0.1" port="6379" db="0" ItemKey="${level:upperCase=true}_${sequenceid}" TTL="365:00:00:00" ConfigurationOptions="name=foo,keepAlive=5">
            <layout xsi:type="JsonLayout" includeEventProperties="true" excludeProperties="Comma-separated list (string)">
                <attribute name="time" layout="${longdate}" />
                <attribute name="level" layout="${level:upperCase=true}"/>
                <attribute name="message" layout="${message}" />
                <attribute name="exception" layout="${exception:format=tostring}" />
            </layout>
        </target>

Output

With the JsonLayout you customize the JSON message fields, in the example above is logged a message with the fields:

  • time: with the longdate of the message
  • level: INFO | DEBUG | etc
  • message: the logged message
  • exception: if any, otherwise null

Without JsonLayout

Without JsonLayout you can specify on the Layout property

<target xsi:type="RedisJson" name="redisjson" host="127.0.0.1" port="6379" db="0" ItemKey="${level:upperCase=true}_${sequenceid}" TTL="365:00:00:00" ConfigurationOptions="name=foo,keepAlive=5"
        layout="${longdate}|${level}|${message} |${all-event-properties} ${exception:format=tostring}">

Output

Without JsonLayout on Redis, a JSON message with:

  • Level: DEBUG | INFO | ecc
  • Exception: If any, otherwise null
  • SequenceId: The id of the message of NLog
  • Timestamp: The timestamp of the message
  • StackTrace: If any, otherwise is null
  • Message: The message with the Layout specified in the nlog.config

Options

Below is the item value configuration:

Host

Type string - Required

The Host name

Port

Type int - Optional default to 6379
The redis port

Db

Type int - Optional default to 0
The redis DB id

Password

Type string - Optional The Redis password

ItemKey

Warning! if not unique it will be skipped without notice

Type (Layout) - Optional default to $"log_{DateTime.Now.Ticks}"
The item key

TTL

Type Timespan format - Optional Set the TTL for the item

ConfigurationOptions

Type string - Optional The additional Redis configuration options

nlog.targets.redisjson's People

Contributors

m4ss1m0g avatar

Watchers

 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.