From 7baa7bcc5689da92678fea0dcf1997cdfb41fe7e Mon Sep 17 00:00:00 2001 From: Michel Michels Date: Wed, 24 Apr 2024 10:29:46 +0200 Subject: [PATCH] Release v8.0.0 --- .github/workflows/dotnet.yml | 43 ++++++ Directory.Build.props | 7 + LICENSE | 2 +- ...sln => MichelMichels.NLog.Targets.Ntfy.sln | 6 +- README.md | 55 ++++---- src/Demo/Demo.csproj | 10 +- ...chelMichels.NLog.Targets.Ntfy.Tests.csproj | 15 ++- .../NtfyLayoutRendererTests.cs | 114 ++++++++-------- .../NtfyTargetTests.cs | 62 ++++----- .../MichelMichels.NLog.Targets.Ntfy.csproj | 22 ++- .../NtfyConstants.cs | 13 +- .../NtfyLayoutRenderer.cs | 69 +++++----- .../NtfyTarget.cs | 127 +++++++++--------- 13 files changed, 295 insertions(+), 250 deletions(-) create mode 100644 .github/workflows/dotnet.yml create mode 100644 Directory.Build.props rename src/MichelMichels.NLog.Targets.Ntfy.sln => MichelMichels.NLog.Targets.Ntfy.sln (80%) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml new file mode 100644 index 0000000..a317475 --- /dev/null +++ b/.github/workflows/dotnet.yml @@ -0,0 +1,43 @@ +# This workflow will build a .NET project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net + +name: .NET + +on: + push: + branches: ["master"] + pull_request: + branches: ["master"] + +jobs: + build: + runs-on: ubuntu-latest + + permissions: + contents: read + issues: read + checks: write + pull-requests: write + + steps: + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + + - name: Restore dependencies + run: dotnet restore + + - name: Build + run: dotnet build + + - name: Test + run: dotnet test --logger:trx + + - name: Publish Test Results + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + files: | + /home/runner/work/nlog-ntfy/nlog-ntfy/src/MichelMichels.NLog.Targets.Ntfy.Tests/TestResults/*.trx diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..36841fd --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,7 @@ + + + 8.0.0.0 + 8.0.0.0 + 8.0.0.0 + + \ No newline at end of file diff --git a/LICENSE b/LICENSE index f8d2820..29de43c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Michel Michels +Copyright (c) 2024 Michel Michels Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/MichelMichels.NLog.Targets.Ntfy.sln b/MichelMichels.NLog.Targets.Ntfy.sln similarity index 80% rename from src/MichelMichels.NLog.Targets.Ntfy.sln rename to MichelMichels.NLog.Targets.Ntfy.sln index 467033c..1a756fd 100644 --- a/src/MichelMichels.NLog.Targets.Ntfy.sln +++ b/MichelMichels.NLog.Targets.Ntfy.sln @@ -3,11 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33205.214 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Demo", "Demo\Demo.csproj", "{D2D5F604-6A74-4DCB-8FCA-0DA884F2E99C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Demo", "src\Demo\Demo.csproj", "{D2D5F604-6A74-4DCB-8FCA-0DA884F2E99C}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MichelMichels.NLog.Targets.Ntfy", "MichelMichels.NLog.Targets.Ntfy\MichelMichels.NLog.Targets.Ntfy.csproj", "{AF38EADD-E120-4A00-BA19-37978C5BFE1F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MichelMichels.NLog.Targets.Ntfy", "src\MichelMichels.NLog.Targets.Ntfy\MichelMichels.NLog.Targets.Ntfy.csproj", "{AF38EADD-E120-4A00-BA19-37978C5BFE1F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MichelMichels.NLog.Targets.Ntfy.Tests", "MichelMichels.NLog.Targets.Ntfy.Tests\MichelMichels.NLog.Targets.Ntfy.Tests.csproj", "{2077289D-7FD9-4911-99A5-4CF91D59D9B1}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MichelMichels.NLog.Targets.Ntfy.Tests", "src\MichelMichels.NLog.Targets.Ntfy.Tests\MichelMichels.NLog.Targets.Ntfy.Tests.csproj", "{2077289D-7FD9-4911-99A5-4CF91D59D9B1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/README.md b/README.md index f5464be..941609f 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,19 @@ -
- NLog logo - Ntfy logo -
-

- NLog target and layout renderer for ntfy.sh -

- -
- - - -
+ +# NLog target and layout renderer for [ntfy.sh](https://ntfy.sh) 🪵 + +[![NuGet Version](https://img.shields.io/nuget/v/MichelMichels.NLog.Targets.Ntfy)](https://www.nuget.org/packages/MichelMichels.NLog.Targets.Ntfy) +[![.NET](https://github.com/MichelMichels/nlog-ntfy/actions/workflows/dotnet.yml/badge.svg)](https://github.com/MichelMichels/nlog-ntfy/actions/workflows/dotnet.yml) + +NLog logo +Ntfy logo
-
- This repository contains a library containing the code for the NLog target and layout renderer, and also a test and demo console library. -
+This repository contains a library containing the code for the NLog target and layout renderer, and also a test and demo console library.

-
+
Table of Contents - [Prerequisites](#prerequisites) @@ -47,8 +40,8 @@ --- ## Prerequisites -- [.NET 7.0](https://dotnet.microsoft.com/en-us/download/dotnet/7.0) -- [NLog 5.1.2+](https://github.com/NLog/NLog) +- [.NET 8.0](https://dotnet.microsoft.com/en-us/download/dotnet/7.0) +- [NLog 5.*](https://github.com/NLog/NLog) - [Ntfy.sh](https://ntfy.sh) ## Building @@ -160,18 +153,18 @@ Example: These are the default values when nothing is changed. -| Setting | Value | -|---------|-------| -| Host | `https://ntfy.sh/` | -| Topic | `nlog-ntfy` | -| Title | `NLog` | -| TraceTags | empty | -| DebugTags | :computer:, `computer` | -| InformationTags | :information_source:, `information_source` | -| WarnTags | :warning:, `warning` | -| ErrorTags | :exclamation:, `exclamation` | -| FatalTags | :skull:, `skull` | -| DefaultTags (fallback) | empty | +| Setting | Value | +| ---------------------- | ------------------------------------------ | +| Host | `https://ntfy.sh/` | +| Topic | `nlog-ntfy` | +| Title | `NLog` | +| TraceTags | empty | +| DebugTags | :computer:, `computer` | +| InformationTags | :information_source:, `information_source` | +| WarnTags | :warning:, `warning` | +| ErrorTags | :exclamation:, `exclamation` | +| FatalTags | :skull:, `skull` | +| DefaultTags (fallback) | empty |

diff --git a/src/Demo/Demo.csproj b/src/Demo/Demo.csproj index 141bd72..313b3d9 100644 --- a/src/Demo/Demo.csproj +++ b/src/Demo/Demo.csproj @@ -2,15 +2,15 @@ Exe - net7.0 + net8.0 enable enable - - - + + + @@ -23,4 +23,4 @@ - + \ No newline at end of file diff --git a/src/MichelMichels.NLog.Targets.Ntfy.Tests/MichelMichels.NLog.Targets.Ntfy.Tests.csproj b/src/MichelMichels.NLog.Targets.Ntfy.Tests/MichelMichels.NLog.Targets.Ntfy.Tests.csproj index 3601ff7..5f5a3b3 100644 --- a/src/MichelMichels.NLog.Targets.Ntfy.Tests/MichelMichels.NLog.Targets.Ntfy.Tests.csproj +++ b/src/MichelMichels.NLog.Targets.Ntfy.Tests/MichelMichels.NLog.Targets.Ntfy.Tests.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 enable enable @@ -9,14 +9,17 @@ - - - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - + \ No newline at end of file diff --git a/src/MichelMichels.NLog.Targets.Ntfy.Tests/NtfyLayoutRendererTests.cs b/src/MichelMichels.NLog.Targets.Ntfy.Tests/NtfyLayoutRendererTests.cs index 27d9dd4..c09efcd 100644 --- a/src/MichelMichels.NLog.Targets.Ntfy.Tests/NtfyLayoutRendererTests.cs +++ b/src/MichelMichels.NLog.Targets.Ntfy.Tests/NtfyLayoutRendererTests.cs @@ -1,77 +1,75 @@ using NLog; -using MichelMichels.NLog.Targets.Ntfy; -namespace MichelMichels.NLog.Targets.Ntfy.Tests +namespace MichelMichels.NLog.Targets.Ntfy.Tests; + +[TestClass] +public class NtfyLayoutRendererTests { - [TestClass] - public class NtfyLayoutRendererTests + [TestMethod] + public void DefaultDateRendered() { - [TestMethod] - public void DefaultDateRendered() - { - // Arrange - var layoutRenderer = new NtfyLayoutRenderer(); + // Arrange + var layoutRenderer = new NtfyLayoutRenderer(); - // Act + // Act - // Assert - Assert.IsTrue(layoutRenderer.IsDateRendered); - } + // Assert + Assert.IsTrue(layoutRenderer.IsDateRendered); + } - [TestMethod] - public void DateNotRendered() + [TestMethod] + public void DateNotRendered() + { + // Arrange + var layoutRenderer = new NtfyLayoutRenderer() { - // Arrange - var layoutRenderer = new NtfyLayoutRenderer() - { - IsDateRendered = false, - }; - var logEvent = new LogEventInfo(LogLevel.Info, "TestLogger", "This is a test message."); + IsDateRendered = false, + }; + var logEvent = new LogEventInfo(LogLevel.Info, "TestLogger", "This is a test message."); - // Act - var result = layoutRenderer.Render(logEvent); + // Act + var result = layoutRenderer.Render(logEvent); - // Assert - Assert.IsFalse(layoutRenderer.IsDateRendered); - Assert.AreEqual(2, result.Split('\n').Length); - } + // Assert + Assert.IsFalse(layoutRenderer.IsDateRendered); + Assert.AreEqual(2, result.Split('\n').Length); + } - [TestMethod] - public void DebugRenderTest() - { - // Arrange - var renderer = new NtfyLayoutRenderer(); - var logEvent = new LogEventInfo(LogLevel.Debug, "TestLogger", "This is a test log event."); - var date = logEvent.TimeStamp; - var dateString = date.ToString("dd/MM/yyyy"); - var timeString = date.ToString("HH:mm"); + [TestMethod] + public void DebugRenderTest() + { + // Arrange + var renderer = new NtfyLayoutRenderer(); + var logEvent = new LogEventInfo(LogLevel.Debug, "TestLogger", "This is a test log event."); + var date = logEvent.TimeStamp; + var dateString = date.ToString("dd/MM/yyyy"); + var timeString = date.ToString("HH:mm"); - // Act - var result = renderer.Render(logEvent); + // Act + var result = renderer.Render(logEvent); - // Assert - Assert.AreEqual(5, result.Split('\n').Length); - Assert.IsTrue(result.Split('\n')[0].Contains(dateString)); - Assert.IsTrue(result.Split('\n')[1].Contains(timeString)); - Assert.IsTrue(result.Split('\n')[3].Contains("This is a test log event.")); - Assert.IsTrue(string.IsNullOrEmpty(result.Split("\n")[4])); - } + // Assert + Assert.AreEqual(5, result.Split('\n').Length); + Assert.IsTrue(result.Split('\n')[0].Contains(dateString)); + Assert.IsTrue(result.Split('\n')[1].Contains(timeString)); + Assert.IsTrue(result.Split('\n')[3].Contains("This is a test log event.")); + Assert.IsTrue(string.IsNullOrEmpty(result.Split("\n")[4])); + } - [TestMethod] - public void ExceptionTest() + [TestMethod] + public void ExceptionTest() + { + // Arrange + var renderer = new NtfyLayoutRenderer(); + var logEvent = new LogEventInfo(LogLevel.Error, "TestLogger", "This is a test log event.") { - // Arrange - var renderer = new NtfyLayoutRenderer(); - var logEvent = new LogEventInfo(LogLevel.Error, "TestLogger", "This is a test log event.") - { - Exception = new ArgumentNullException(), - }; + Exception = new ArgumentNullException(), + }; - // Act - var result = renderer.Render(logEvent); + // Act + var result = renderer.Render(logEvent); - // Assert - Assert.AreEqual(7, result.Split('\n').Length); - } + // Assert + Assert.AreEqual(7, result.Split('\n').Length); } } \ No newline at end of file diff --git a/src/MichelMichels.NLog.Targets.Ntfy.Tests/NtfyTargetTests.cs b/src/MichelMichels.NLog.Targets.Ntfy.Tests/NtfyTargetTests.cs index c45ce7c..d31d3bd 100644 --- a/src/MichelMichels.NLog.Targets.Ntfy.Tests/NtfyTargetTests.cs +++ b/src/MichelMichels.NLog.Targets.Ntfy.Tests/NtfyTargetTests.cs @@ -1,46 +1,38 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using MichelMichels.NLog.Targets.Ntfy; +namespace MichelMichels.NLog.Targets.Ntfy.Tests; -namespace MichelMichels.NLog.Targets.Ntfy.Tests +[TestClass] +public class NtfyTargetTests { - [TestClass] - public class NtfyTargetTests + [TestMethod] + public void DefaultConstructorTest() { - [TestMethod] - public void DefaultConstructorTest() - { - // Arrange - var target = new NtfyTarget(); + // Arrange + var target = new NtfyTarget(); - // Act + // Act - // Assert - Assert.AreEqual("nlog-ntfy", target.Topic); - Assert.AreEqual("NLog", target.Title); - Assert.AreEqual(@"https://ntfy.sh/", target.Host); - } + // Assert + Assert.AreEqual("nlog-ntfy", target.Topic); + Assert.AreEqual("NLog", target.Title); + Assert.AreEqual(@"https://ntfy.sh/", target.Host); + } - [TestMethod] - public void DefaultTagsTest() - { - // Arrange - var target = new NtfyTarget(); + [TestMethod] + public void DefaultTagsTest() + { + // Arrange + var target = new NtfyTarget(); - // Act + // Act - // Assert - Assert.AreEqual("", target.DefaultTags); - Assert.AreEqual("", target.TraceTags); - Assert.AreEqual("computer", target.DebugTags); - Assert.AreEqual("information_source", target.InformationTags); - Assert.AreEqual("warning", target.WarnTags); - Assert.AreEqual("exclamation", target.ErrorTags); - Assert.AreEqual("skull", target.FatalTags); + // Assert + Assert.AreEqual("", target.DefaultTags); + Assert.AreEqual("", target.TraceTags); + Assert.AreEqual("computer", target.DebugTags); + Assert.AreEqual("information_source", target.InformationTags); + Assert.AreEqual("warning", target.WarnTags); + Assert.AreEqual("exclamation", target.ErrorTags); + Assert.AreEqual("skull", target.FatalTags); - } } } diff --git a/src/MichelMichels.NLog.Targets.Ntfy/MichelMichels.NLog.Targets.Ntfy.csproj b/src/MichelMichels.NLog.Targets.Ntfy/MichelMichels.NLog.Targets.Ntfy.csproj index b4d9d2a..b2f84a5 100644 --- a/src/MichelMichels.NLog.Targets.Ntfy/MichelMichels.NLog.Targets.Ntfy.csproj +++ b/src/MichelMichels.NLog.Targets.Ntfy/MichelMichels.NLog.Targets.Ntfy.csproj @@ -1,19 +1,31 @@  - net7.0 + net8.0 enable enable True - 1.0.0 NLog target for ntfy.sh Michel Michels - This package contains an NLog target and a layout renderer for the ntfy.sh service. + This package contains an NLog target and a layout renderer for the ntfy.sh service. https://github.com/MichelMichels/nlog-ntfy + MIT + README.md + + - Release 8.0.0 to reflect .NET version support + - Floating version used of NLog (5.*) + + https://github.com/MichelMichels/nlog-ntfy + git + nlog ntfy ntfy.sh target logging log - + - + + + + + \ No newline at end of file diff --git a/src/MichelMichels.NLog.Targets.Ntfy/NtfyConstants.cs b/src/MichelMichels.NLog.Targets.Ntfy/NtfyConstants.cs index d9fb5a4..7643fec 100644 --- a/src/MichelMichels.NLog.Targets.Ntfy/NtfyConstants.cs +++ b/src/MichelMichels.NLog.Targets.Ntfy/NtfyConstants.cs @@ -1,9 +1,8 @@ -namespace MichelMichels.NLog.Targets.Ntfy +namespace MichelMichels.NLog.Targets.Ntfy; + +public static class NtfyHeaders { - public static class NtfyHeaders - { - public const string Title = "Title"; - public const string Priority = "Priority"; - public const string Tags = "Tags"; - } + public const string Title = "Title"; + public const string Priority = "Priority"; + public const string Tags = "Tags"; } diff --git a/src/MichelMichels.NLog.Targets.Ntfy/NtfyLayoutRenderer.cs b/src/MichelMichels.NLog.Targets.Ntfy/NtfyLayoutRenderer.cs index dc9a8eb..f896747 100644 --- a/src/MichelMichels.NLog.Targets.Ntfy/NtfyLayoutRenderer.cs +++ b/src/MichelMichels.NLog.Targets.Ntfy/NtfyLayoutRenderer.cs @@ -2,49 +2,48 @@ using NLog.LayoutRenderers; using System.Text; -namespace MichelMichels.NLog.Targets.Ntfy +namespace MichelMichels.NLog.Targets.Ntfy; + +[LayoutRenderer("ntfy")] +public sealed class NtfyLayoutRenderer : LayoutRenderer { - [LayoutRenderer("ntfy")] - public sealed class NtfyLayoutRenderer : LayoutRenderer - { - public bool IsDateRendered { get; set; } = true; + public bool IsDateRendered { get; set; } = true; - protected override void Append(StringBuilder builder, LogEventInfo logEvent) - { - RenderDate(builder, logEvent); - RenderMessage(builder, logEvent); - RenderException(builder, logEvent); - RenderStackTrace(builder, logEvent); - } + protected override void Append(StringBuilder builder, LogEventInfo logEvent) + { + RenderDate(builder, logEvent); + RenderMessage(builder, logEvent); + RenderException(builder, logEvent); + RenderStackTrace(builder, logEvent); + } - private void RenderDate(StringBuilder builder, LogEventInfo logEvent) - { - if (IsDateRendered) - { - builder.AppendLine($"Date: {logEvent.TimeStamp:dd/MM/yyyy}"); - builder.AppendLine($"Time: {logEvent.TimeStamp:HH:mm}"); - builder.AppendLine(); - } - } - private void RenderMessage(StringBuilder builder, LogEventInfo logEvent) + private void RenderDate(StringBuilder builder, LogEventInfo logEvent) + { + if (IsDateRendered) { - builder.AppendLine($"{logEvent.Message}"); + builder.AppendLine($"Date: {logEvent.TimeStamp:dd/MM/yyyy}"); + builder.AppendLine($"Time: {logEvent.TimeStamp:HH:mm}"); + builder.AppendLine(); } - private void RenderException(StringBuilder builder, LogEventInfo logEvent) + } + private void RenderMessage(StringBuilder builder, LogEventInfo logEvent) + { + builder.AppendLine($"{logEvent.Message}"); + } + private void RenderException(StringBuilder builder, LogEventInfo logEvent) + { + if (logEvent.Exception != null) { - if (logEvent.Exception != null) - { - builder.AppendLine(); - builder.AppendLine($"Exception: {logEvent.Exception.ToString()}"); - } + builder.AppendLine(); + builder.AppendLine($"Exception: {logEvent.Exception.ToString()}"); } - private void RenderStackTrace(StringBuilder builder, LogEventInfo logEvent) + } + private void RenderStackTrace(StringBuilder builder, LogEventInfo logEvent) + { + if (logEvent.HasStackTrace) { - if (logEvent.HasStackTrace) - { - builder.AppendLine(); - builder.AppendLine($"StackTrace: {logEvent.StackTrace.ToString()}"); - } + builder.AppendLine(); + builder.AppendLine($"StackTrace: {logEvent.StackTrace.ToString()}"); } } } diff --git a/src/MichelMichels.NLog.Targets.Ntfy/NtfyTarget.cs b/src/MichelMichels.NLog.Targets.Ntfy/NtfyTarget.cs index 5870315..e9842f8 100644 --- a/src/MichelMichels.NLog.Targets.Ntfy/NtfyTarget.cs +++ b/src/MichelMichels.NLog.Targets.Ntfy/NtfyTarget.cs @@ -2,85 +2,84 @@ using NLog.Config; using NLog.Targets; -namespace MichelMichels.NLog.Targets.Ntfy +namespace MichelMichels.NLog.Targets.Ntfy; + +[Target("Ntfy")] +public sealed class NtfyTarget : AsyncTaskTarget { - [Target("Ntfy")] - public sealed class NtfyTarget : AsyncTaskTarget + private HttpClient? httpClient; + + public NtfyTarget() { - private HttpClient? httpClient; + Topic = "nlog-ntfy"; + Title = "NLog"; + Host = @"https://ntfy.sh/"; + } - public NtfyTarget() - { - Topic = "nlog-ntfy"; - Title = "NLog"; - Host = @"https://ntfy.sh/"; - } + [RequiredParameter] + public string Topic { get; set; } - [RequiredParameter] - public string Topic { get; set; } + [RequiredParameter] + public string Title { get; set; } - [RequiredParameter] - public string Title { get; set; } + [RequiredParameter] + public string Host { get; set; } - [RequiredParameter] - public string Host { get; set; } + public string TraceTags { get; set; } = ""; + public string DebugTags { get; set; } = "computer"; + public string InformationTags { get; set; } = "information_source"; + public string WarnTags { get; set; } = "warning"; + public string ErrorTags { get; set; } = "exclamation"; + public string FatalTags { get; set; } = "skull"; + public string DefaultTags { get; set; } = ""; - public string TraceTags { get; set; } = ""; - public string DebugTags { get; set; } = "computer"; - public string InformationTags { get; set; } = "information_source"; - public string WarnTags { get; set; } = "warning"; - public string ErrorTags { get; set; } = "exclamation"; - public string FatalTags { get; set; } = "skull"; - public string DefaultTags { get; set; } = ""; + protected override void InitializeTarget() + { + base.InitializeTarget(); - protected override void InitializeTarget() + httpClient = new HttpClient() { - base.InitializeTarget(); - - httpClient = new HttpClient() - { - BaseAddress = new Uri(Host), - }; - } + BaseAddress = new Uri(Host), + }; + } - protected override void CloseTarget() - { - httpClient?.Dispose(); - base.CloseTarget(); - } + protected override void CloseTarget() + { + httpClient?.Dispose(); + base.CloseTarget(); + } - protected override Task WriteAsyncTask(LogEventInfo logEvent, CancellationToken token) - { - return SendTheMessageToRemoteHost(logEvent); - } + protected override Task WriteAsyncTask(LogEventInfo logEvent, CancellationToken token) + { + return SendTheMessageToRemoteHost(logEvent); + } - private async Task SendTheMessageToRemoteHost(LogEventInfo logEvent) + private async Task SendTheMessageToRemoteHost(LogEventInfo logEvent) + { + if (httpClient == null) { - if(httpClient == null) - { - return; - } + return; + } - var request = new HttpRequestMessage(HttpMethod.Post, Topic); - request.Headers.Add(NtfyHeaders.Title, $"{logEvent.Level.Name} - {Title}"); - request.Headers.Add(NtfyHeaders.Tags, GetTags(logEvent.Level)); - request.Content = new StringContent(RenderLogEvent(this.Layout, logEvent)); + var request = new HttpRequestMessage(HttpMethod.Post, Topic); + request.Headers.Add(NtfyHeaders.Title, $"{logEvent.Level.Name} - {Title}"); + request.Headers.Add(NtfyHeaders.Tags, GetTags(logEvent.Level)); + request.Content = new StringContent(RenderLogEvent(this.Layout, logEvent)); - await httpClient.SendAsync(request); - } + await httpClient.SendAsync(request); + } - private string GetTags(LogLevel logLevel) - { - return logLevel.Name switch - { - nameof(LogLevel.Trace) => TraceTags, - nameof(LogLevel.Debug) => DebugTags, - nameof(LogLevel.Info) => InformationTags, - nameof(LogLevel.Warn) => WarnTags, - nameof(LogLevel.Error) => ErrorTags, - nameof(LogLevel.Fatal) => FatalTags, - _ => DefaultTags, - }; - } + private string GetTags(LogLevel logLevel) + { + return logLevel.Name switch + { + nameof(LogLevel.Trace) => TraceTags, + nameof(LogLevel.Debug) => DebugTags, + nameof(LogLevel.Info) => InformationTags, + nameof(LogLevel.Warn) => WarnTags, + nameof(LogLevel.Error) => ErrorTags, + nameof(LogLevel.Fatal) => FatalTags, + _ => DefaultTags, + }; } }