NLog.Targets.RedisJson 1.0.2

dotnet add package NLog.Targets.RedisJson --version 1.0.2
NuGet\Install-Package NLog.Targets.RedisJson -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NLog.Targets.RedisJson" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NLog.Targets.RedisJson --version 1.0.2
#r "nuget: NLog.Targets.RedisJson, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NLog.Targets.RedisJson as a Cake Addin
#addin nuget:?package=NLog.Targets.RedisJson&version=1.0.2

// Install NLog.Targets.RedisJson as a Cake Tool
#tool nuget:?package=NLog.Targets.RedisJson&version=1.0.2

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

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 209 12/4/2023
1.0.0 91 12/4/2023

ChangeLog:

Initial release