Skip to content

Commit

Permalink
Merge pull request #6 from jjm-one/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jonas-merkle committed Jul 4, 2023
2 parents b5b8981 + 66c20b5 commit 376d926
Show file tree
Hide file tree
Showing 18 changed files with 444 additions and 72 deletions.
49 changes: 18 additions & 31 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,7 @@ jobs:
- name: Build
run: dotnet build --no-restore -c Release
- name: Test
run: dotnet test --no-build --verbosity normal
#- name: Upload artifact
# uses: actions/upload-artifact@v3
# with:
# name: release-buid
# path: |
# ./jjm-one_jjm.one.Serilog.Extensions.Logging.Helpers/bin/Release/*.nupkg
# retention-days: 1
run: dotnet test --no-build -c Release --verbosity normal

sonarcloud:
name: Build and analyze with SonarCloud
Expand All @@ -89,6 +82,13 @@ jobs:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Cache dotnet-coverage
id: cache-dotnet-coverage
uses: actions/cache@v1
with:
path: .\.dotnet-coverage\dotnet-coverage
key: ${{ runner.os }}-dotnet-coverage
restore-keys: ${{ runner.os }}-dotnet-coverage
- name: Setup dotNET
uses: actions/setup-dotnet@v3
with:
Expand All @@ -99,39 +99,26 @@ jobs:
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- name: Install dotnet-coverage
if: steps.cache-dotnet-coverage.outputs.cache-hit != 'true'
shell: powershell
run: |
New-Item -Path .\.dotnet-coverage\dotnet-coverage -ItemType Directory
dotnet tool update dotnet-coverage --tool-path .\.dotnet-coverage\dotnet-coverage
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
cd .\src
.\..\.sonar\scanner\dotnet-sonarscanner begin /k:"jjm-one_jjm.one.Serilog.Extensions.Logging.Helpers" /o:"jjm-one" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
.\..\.sonar\scanner\dotnet-sonarscanner begin /k:"jjm-one_jjm.one.Serilog.Extensions.Logging.Helpers" /o:"jjm-one" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
dotnet restore
dotnet build --no-restore
dotnet build --no-restore -c Debug
.\..\.dotnet-coverage\dotnet-coverage\dotnet-coverage collect "dotnet test --no-build --verbosity normal" -f xml -o "coverage.xml"
cat coverage.xml
.\..\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
#publish-nuget:
# name: Publish the NuGet package
# needs: [build-and-test-debug, build-and-test-release, sonarcloud, publish-doc]
# if: github.ref_type == 'tag' && startsWith(github.event.ref, 'refs/tags/version-')
# runs-on: ubuntu-latest
# steps:
# - name: Download a single artifact
# uses: actions/download-artifact@v3
# with:
# name: release-buid
# - name: Setup dotNET
# uses: actions/setup-dotnet@v3
# with:
# dotnet-version: 7.x
# - name: Publish the package to nuget.org
# run: |
# ls -la
# #run: dotnet nuget push */bin/Release/*.nupkg -k $NUGET_AUTH_TOKEN -s https://api.nuget.org/v3/index.json
# #env:
# # NUGET_AUTH_TOKEN: ${{ secrets.NUGET_TOKEN }}

publish-doc:
name: Publish Documentation
needs: [build-and-test-debug]
Expand Down
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROJECT_NAME = jjm.one.Serilog.Extensions.Logging.Helpers
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 1.0.3
PROJECT_NUMBER = 1.2.0

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ A collection of helper functions for the [Serilog.Extensions.Logging](https://ww
- [Status](#status)
- [Table of contents](#table-of-contents)
- [Nuget Package](#nuget-package)
- [Installing the Nuget Package](#installing-the-nuget-package)
- [Usage](#usage)
- [Use function logging](#use-function-logging)
- [Output of function logging](#output-of-function-logging)
Expand All @@ -26,6 +27,18 @@ A collection of helper functions for the [Serilog.Extensions.Logging](https://ww

You can get the latest version of this software as a nuget package form [nuget.org](https://www.nuget.org/packages/jjm.one.Serilog.Extensions.Logging.Helpers/)

### Installing the Nuget Package

| Tool | Command/Code |
|----------------------|--------------|
| Package Manager | ```PM> Install-Package jjm.one.Serilog.Extensions.Logging.Helper -Version X.Y.Z``` |
| .NET CLI | ```> dotnet add package jjm.one.Serilog.Extensions.Logging.Helper --version X.Y.Z``` |
| PackageReference | ```<PackageReference Include="jjm.one.Serilog.Extensions.Logging.Helper" Version="X.Y.Z" />``` |
| Package CLI | ```> paket add jjm.one.Serilog.Extensions.Logging.Helper --version X.Y.Z``` |
| Script & Interactive | ```> #r "nuget: jjm.one.Serilog.Extensions.Logging.Helper, X.Y.Z"``` |
| Cake as Addin | ```#addin nuget:?package=jjm.one.Serilog.Extensions.Logging.Helper&version=X.Y.Z``` |
| Cake as Tool | ```#tool nuget:?package=jjm.one.Serilog.Extensions.Logging.Helper&version=X.Y.Z``` |

## Usage

### Use function logging
Expand All @@ -37,7 +50,10 @@ class MyClass {
void MyFancyFunction() {

// log the function call
// log the function call (minimal parameters)
Log.Logger.LogFctCall();

// log the function call (full parameters)
Log.Logger.LogFctCall(GetType(), MethodBase.GetCurrentMethod(), LogEventLevel.Debug);

try {
Expand All @@ -46,7 +62,10 @@ class MyClass {
}
catch (Exception exc) {

// Log the exception
// Log the exception (minimal parameters)
Log.Logger.LogExcInFctCall(exc);

// Log the exception (full parameters)
Log.Logger.LogExcInFctCall(exc, GetType(), MethodBase.GetCurrentMethod(), "My custom exception message!", LogEventLevel.Error);
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
using System;
using System.Reflection;
using Moq;
using Serilog.Events;
using Serilog;

namespace jjm.one.Serilog.Extensions.Logging.Helpers.Tests.FunctionLogging;

/// <summary>
/// This class contains the tests for the <see cref="FunctionLogging"/> class.
/// </summary>
public class FunctionLoggingTests
{
#region private members

private readonly Mock<ILogger> _logger;

#endregion

#region ctors

/// <summary>
/// The default constructor of the <see cref="FunctionLoggingTests"/> class.
/// </summary>
public FunctionLoggingTests()
{
_logger = new Mock<ILogger>();
}

#endregion

#region tests

/// <summary>
/// 1. test of the LogFctCall function.
/// </summary>
[Fact]
public void LogFctCallTest1()
{
// arrange
_logger.Setup(x => x.Write(LogEventLevel.Debug,
It.IsAny<string>(), It.IsAny<object?[]?>())).Verifiable();

// act
_logger.Object.LogFctCall();

// assert
_logger.Verify(x => x.Write(LogEventLevel.Debug,
"Function called: {ClassName} -> {FctName}",
nameof(FunctionLoggingTests), nameof(LogFctCallTest1)),
Times.Once);
}

/// <summary>
/// 2. test of the LogFctCall function.
/// </summary>
[Fact]
public void LogFctCallTest2()
{
// arrange
_logger.Setup(x => x.Write(LogEventLevel.Debug,
It.IsAny<string>(), It.IsAny<object?[]?>())).Verifiable();

// act
_logger.Object.LogFctCall(GetType(), MethodBase.GetCurrentMethod());

// assert
_logger.Verify(x => x.Write(LogEventLevel.Debug,
"Function called: {ClassName} -> {FctName}",
nameof(FunctionLoggingTests), nameof(LogFctCallTest2)),
Times.Once);
}

/// <summary>
/// 1. test of the LogExcInFctCall function.
/// </summary>
[Fact]
public void LogExcInFctCallTest1()
{
// arrange
var exc = new Exception("Test");
_logger.Setup(x => x.Write(LogEventLevel.Debug, It.IsAny<Exception>(),
It.IsAny<string>(), It.IsAny<object?[]?>())).Verifiable();

// act
_logger.Object.LogExcInFctCall(exc);

// assert
_logger.Verify(x => x.Write(LogEventLevel.Error,
It.Is<Exception>(e => e == exc),
"Exception thrown in: {ClassName} -> {FctName}{CustomMsg}",
nameof(FunctionLoggingTests), nameof(LogExcInFctCallTest1),
string.Empty),
Times.Once);
}

/// <summary>
/// 2. test of the LogExcInFctCall function.
/// </summary>
[Fact]
public void LogExcInFctCallTest2()
{
// arrange
var exc = new Exception("Test");
_logger.Setup(x => x.Write(LogEventLevel.Debug, It.IsAny<Exception>(),
It.IsAny<string>(), It.IsAny<object?[]?>())).Verifiable();

// act
_logger.Object.LogExcInFctCall(exc, "TestMSG");

// assert
_logger.Verify(x => x.Write(LogEventLevel.Error,
It.Is<Exception>(e => e == exc),
"Exception thrown in: {ClassName} -> {FctName}{CustomMsg}",
nameof(FunctionLoggingTests), nameof(LogExcInFctCallTest2),
"\nTestMSG"),
Times.Once);
}

/// <summary>
/// 3. test of the LogExcInFctCall function.
/// </summary>
[Fact]
public void LogExcInFctCallTest3()
{
// arrange
var exc = new Exception("Test");
_logger.Setup(x => x.Write(LogEventLevel.Debug, It.IsAny<Exception>(),
It.IsAny<string>(), It.IsAny<object?[]?>())).Verifiable();

// act
_logger.Object.LogExcInFctCall(exc, GetType(),
MethodBase.GetCurrentMethod());

// assert
_logger.Verify(x => x.Write(LogEventLevel.Error,
It.Is<Exception>(e => e == exc),
"Exception thrown in: {ClassName} -> {FctName}{CustomMsg}",
nameof(FunctionLoggingTests), nameof(LogExcInFctCallTest3),
string.Empty),
Times.Once);
}

/// <summary>
/// 4. test of the LogExcInFctCall function.
/// </summary>
[Fact]
public void LogExcInFctCallTest4()
{
// arrange
var exc = new Exception("Test");
_logger.Setup(x => x.Write(LogEventLevel.Debug, It.IsAny<Exception>(),
It.IsAny<string>(), It.IsAny<object?[]?>())).Verifiable();

// act
_logger.Object.LogExcInFctCall(exc, GetType(),
MethodBase.GetCurrentMethod(), "TestMSG");

// assert
_logger.Verify(x => x.Write(LogEventLevel.Error,
It.Is<Exception>(e => e == exc),
"Exception thrown in: {ClassName} -> {FctName}{CustomMsg}",
nameof(FunctionLoggingTests), nameof(LogExcInFctCallTest4),
"\nTestMSG"),
Times.Once);
}

#endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
Binary file not shown.
Loading

0 comments on commit 376d926

Please sign in to comment.