Skip to content

Commit

Permalink
Release v8.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelMichels committed Apr 24, 2024
1 parent 96b35df commit 7baa7bc
Show file tree
Hide file tree
Showing 13 changed files with 295 additions and 250 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<PropertyGroup>
<Version>8.0.0.0</Version>
<FileVersion>8.0.0.0</FileVersion>
<InformationalVersion>8.0.0.0</InformationalVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 24 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
<div align="center">
<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" />
</div>
<h1 align="center">
NLog target and layout renderer for <a href="https://ntfy.sh/">ntfy.sh</a>
</h1>

<div align="center">
<a href="https://www.nuget.org/packages/MichelMichels.NLog.Targets.Ntfy">
<img src="https://img.shields.io/nuget/v/MichelMichels.NLog.Targets.Ntfy"/>
</a>
</div>
<!-- omit in toc -->
# 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)

<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 />

<div align="center">
This repository contains a library containing the code for the NLog target and layout renderer, and also a test and demo console library.
</div>
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 open="open">
<details>
<summary>Table of Contents</summary>

- [Prerequisites](#prerequisites)
Expand All @@ -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
Expand Down Expand Up @@ -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 |

<br />
<hr>
Expand Down
10 changes: 5 additions & 5 deletions src/Demo/Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
</ItemGroup>

<ItemGroup>
Expand All @@ -23,4 +23,4 @@
</None>
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MichelMichels.NLog.Targets.Ntfy\MichelMichels.NLog.Targets.Ntfy.csproj" />
</ItemGroup>

</Project>
</Project>
114 changes: 56 additions & 58 deletions src/MichelMichels.NLog.Targets.Ntfy.Tests/NtfyLayoutRendererTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading

0 comments on commit 7baa7bc

Please sign in to comment.