MichelMichels.NLog.Targets.Ntfy 8.0.0

Prefix Reserved
dotnet add package MichelMichels.NLog.Targets.Ntfy --version 8.0.0                
NuGet\Install-Package MichelMichels.NLog.Targets.Ntfy -Version 8.0.0                
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="MichelMichels.NLog.Targets.Ntfy" Version="8.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MichelMichels.NLog.Targets.Ntfy --version 8.0.0                
#r "nuget: MichelMichels.NLog.Targets.Ntfy, 8.0.0"                
#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 MichelMichels.NLog.Targets.Ntfy as a Cake Addin
#addin nuget:?package=MichelMichels.NLog.Targets.Ntfy&version=8.0.0

// Install MichelMichels.NLog.Targets.Ntfy as a Cake Tool
#tool nuget:?package=MichelMichels.NLog.Targets.Ntfy&version=8.0.0                

NLog target and layout renderer for ntfy.sh 🪵

NuGet Version .NET

<img alt="NLog logo" src="https://raw.githubusercontent.com/NLog/NLog.github.io/master/images/NLog-logo-only_small.png" height="64" /> <img alt="Ntfy logo" src="https://raw.githubusercontent.com/binwiederhier/ntfy/main/web/public/static/images/ntfy.png" height="64" />

<br />

This repository contains a library containing the code for the NLog target and layout renderer, and also a test and demo console library. <br /> <br />

<details> <summary>Table of Contents</summary>

</details>


Prerequisites

Building

Use Visual Studio 2022 to build the project.

Installation

Get the NuGet package from nuget.org or search for MichelMichels.NLog.Targets.Ntfy in the GUI package manager in Visual Studio.

You can also use the cli of the package manager with following command:

Install-Package MichelMichels.NLog.Targets.Ntfy

<br /> <hr>

Getting started

⚠️ This assumes you already have a nlog.config file. For more information to setup NLog, see the NLog wiki.

These instructions will add information to your NLog configuration file to make our target available. In this setup, the default nlog.config is used and nothing is removed.

ℹ️ For brevity, only the added or edited elements are displayed in these code snippets.

1. Add extension

<extensions>
    <add assembly="MichelMichels.NLog.Targets.Ntfy" />
</extensions>

2. Add target

<targets>
    <target xsi:type="Ntfy" name="logntfy" />
</targets>

3. Add or edit rule

In this snippet, logntfy (the name of the target configured above) is added to the writeTo attribute. The others are default and are not necessary for this target to work.

<rules>
    <logger name="*" minlevel="Trace" writeTo="logfile,logconsole,logntfy" />
</rules>

4. Done!

After these steps, you can subscribe to the nlog-ntfy topic and you will see the notifications come in. More information is included below to change the default settings, but you can use this as-is. I only recommend to change the topic attribute in the target configuration to something only you know. See Configuration > Topic for instructions.

<br /> <hr>

Configuration

Host

ℹ️ The default value for the host is https://ntfy.sh/.

If you want to use another ntfy-server, you can change the host attribute on the target.

Example:

<target xsi:type="Ntfy" name="logntfy" host="https://other.ntfy.server/"  />

Notification title

ℹ️ The default value for the title is NLog.

The notification title contains 3 parts:

  • An emoji linked to the LogLevel (tags)
  • The string-value of the LogLevel (f.e. 'Debug')
  • The value in the 'Title' attribute (f.e. your app name)

The notification title of your Ntfy notification for a debug log message with default configuration would be:

:computer: Debug - NLog

In previous example, the NLog part will be changed when setting the Title attribute on the target.

Notification title icons/tags

You can change the title icons (or 'tags') by setting the *Tags attributes. See the emoji shortcodes on ntfy.sh for supported emoji-tags. See the defaults table for the default values.

Topic

ℹ️ The default value for the topic is nlog-ntfy.

⚠️ You should change the topic if you don't want other people to read your logging.

Set the topic attribute on the target to change to a ntfy topic of your choice. In the example below, the topic is changed to my-app-logging.

Example:

<target xsi:type="Ntfy" name="logntfy" topic="my-app-logging"  />

Defaults

These are the default values when nothing is changed.

Setting Value
Host https://ntfy.sh/
Topic nlog-ntfy
Title NLog
TraceTags empty
DebugTags 💻, computer
InformationTags ℹ️, information_source
WarnTags ⚠️, warning
ErrorTags ❗, exclamation
FatalTags 💀, skull
DefaultTags (fallback) empty

<br /> <hr>

LayoutRenderer

Any layout renderer can be used, but I also included one. The body of the notification will be the render output. To use the renderer included in this package you can add following attribute and value to the Ntfy target:

layout="${ntfy}"

This produces following output:

Date: dd/mm/yyyy
Time: hh:mm

{logMessage}

Exception: {exception.ToString()}

StackTrace: {stackTrace}

The exception and stacktrace output is only enabled if this info is present in the log event.

Disable date output

Date and time output can be disabled by using the isdaterendered option on the layoutrenderer.

layout="${ntfy:isdaterendered=false}"

<br /> <hr>

Screenshots

Coming soon™

<br /> <hr>

Credits

Written by Michel Michels.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

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
8.0.0 537 4/24/2024
1.0.0 945 2/20/2023

- Release 8.0.0 to reflect .NET version support
     - Floating version used of NLog (5.*)