Skip to content

Commit 376d926

Browse files
authored
Merge pull request #6 from jjm-one/develop
Develop
2 parents b5b8981 + 66c20b5 commit 376d926

18 files changed

+444
-72
lines changed

.github/workflows/dotnet.yml

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,7 @@ jobs:
5555
- name: Build
5656
run: dotnet build --no-restore -c Release
5757
- name: Test
58-
run: dotnet test --no-build --verbosity normal
59-
#- name: Upload artifact
60-
# uses: actions/upload-artifact@v3
61-
# with:
62-
# name: release-buid
63-
# path: |
64-
# ./jjm-one_jjm.one.Serilog.Extensions.Logging.Helpers/bin/Release/*.nupkg
65-
# retention-days: 1
58+
run: dotnet test --no-build -c Release --verbosity normal
6659

6760
sonarcloud:
6861
name: Build and analyze with SonarCloud
@@ -89,6 +82,13 @@ jobs:
8982
path: .\.sonar\scanner
9083
key: ${{ runner.os }}-sonar-scanner
9184
restore-keys: ${{ runner.os }}-sonar-scanner
85+
- name: Cache dotnet-coverage
86+
id: cache-dotnet-coverage
87+
uses: actions/cache@v1
88+
with:
89+
path: .\.dotnet-coverage\dotnet-coverage
90+
key: ${{ runner.os }}-dotnet-coverage
91+
restore-keys: ${{ runner.os }}-dotnet-coverage
9292
- name: Setup dotNET
9393
uses: actions/setup-dotnet@v3
9494
with:
@@ -99,39 +99,26 @@ jobs:
9999
run: |
100100
New-Item -Path .\.sonar\scanner -ItemType Directory
101101
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
102+
- name: Install dotnet-coverage
103+
if: steps.cache-dotnet-coverage.outputs.cache-hit != 'true'
104+
shell: powershell
105+
run: |
106+
New-Item -Path .\.dotnet-coverage\dotnet-coverage -ItemType Directory
107+
dotnet tool update dotnet-coverage --tool-path .\.dotnet-coverage\dotnet-coverage
102108
- name: Build and analyze
103109
env:
104110
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
105111
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
106112
shell: powershell
107113
run: |
108114
cd .\src
109-
.\..\.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"
115+
.\..\.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
110116
dotnet restore
111-
dotnet build --no-restore
117+
dotnet build --no-restore -c Debug
118+
.\..\.dotnet-coverage\dotnet-coverage\dotnet-coverage collect "dotnet test --no-build --verbosity normal" -f xml -o "coverage.xml"
119+
cat coverage.xml
112120
.\..\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
113121
114-
#publish-nuget:
115-
# name: Publish the NuGet package
116-
# needs: [build-and-test-debug, build-and-test-release, sonarcloud, publish-doc]
117-
# if: github.ref_type == 'tag' && startsWith(github.event.ref, 'refs/tags/version-')
118-
# runs-on: ubuntu-latest
119-
# steps:
120-
# - name: Download a single artifact
121-
# uses: actions/download-artifact@v3
122-
# with:
123-
# name: release-buid
124-
# - name: Setup dotNET
125-
# uses: actions/setup-dotnet@v3
126-
# with:
127-
# dotnet-version: 7.x
128-
# - name: Publish the package to nuget.org
129-
# run: |
130-
# ls -la
131-
# #run: dotnet nuget push */bin/Release/*.nupkg -k $NUGET_AUTH_TOKEN -s https://api.nuget.org/v3/index.json
132-
# #env:
133-
# # NUGET_AUTH_TOKEN: ${{ secrets.NUGET_TOKEN }}
134-
135122
publish-doc:
136123
name: Publish Documentation
137124
needs: [build-and-test-debug]

Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ PROJECT_NAME = jjm.one.Serilog.Extensions.Logging.Helpers
4848
# could be handy for archiving the generated documentation or if some version
4949
# control system is used.
5050

51-
PROJECT_NUMBER = 1.0.3
51+
PROJECT_NUMBER = 1.2.0
5252

5353
# Using the PROJECT_BRIEF tag one can provide an optional one line description
5454
# for a project that appears at the top of each page and should give viewer a

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ A collection of helper functions for the [Serilog.Extensions.Logging](https://ww
1616
- [Status](#status)
1717
- [Table of contents](#table-of-contents)
1818
- [Nuget Package](#nuget-package)
19+
- [Installing the Nuget Package](#installing-the-nuget-package)
1920
- [Usage](#usage)
2021
- [Use function logging](#use-function-logging)
2122
- [Output of function logging](#output-of-function-logging)
@@ -26,6 +27,18 @@ A collection of helper functions for the [Serilog.Extensions.Logging](https://ww
2627

2728
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/)
2829

30+
### Installing the Nuget Package
31+
32+
| Tool | Command/Code |
33+
|----------------------|--------------|
34+
| Package Manager | ```PM> Install-Package jjm.one.Serilog.Extensions.Logging.Helper -Version X.Y.Z``` |
35+
| .NET CLI | ```> dotnet add package jjm.one.Serilog.Extensions.Logging.Helper --version X.Y.Z``` |
36+
| PackageReference | ```<PackageReference Include="jjm.one.Serilog.Extensions.Logging.Helper" Version="X.Y.Z" />``` |
37+
| Package CLI | ```> paket add jjm.one.Serilog.Extensions.Logging.Helper --version X.Y.Z``` |
38+
| Script & Interactive | ```> #r "nuget: jjm.one.Serilog.Extensions.Logging.Helper, X.Y.Z"``` |
39+
| Cake as Addin | ```#addin nuget:?package=jjm.one.Serilog.Extensions.Logging.Helper&version=X.Y.Z``` |
40+
| Cake as Tool | ```#tool nuget:?package=jjm.one.Serilog.Extensions.Logging.Helper&version=X.Y.Z``` |
41+
2942
## Usage
3043

3144
### Use function logging
@@ -37,7 +50,10 @@ class MyClass {
3750
3851
void MyFancyFunction() {
3952

40-
// log the function call
53+
// log the function call (minimal parameters)
54+
Log.Logger.LogFctCall();
55+
56+
// log the function call (full parameters)
4157
Log.Logger.LogFctCall(GetType(), MethodBase.GetCurrentMethod(), LogEventLevel.Debug);
4258

4359
try {
@@ -46,7 +62,10 @@ class MyClass {
4662
}
4763
catch (Exception exc) {
4864

49-
// Log the exception
65+
// Log the exception (minimal parameters)
66+
Log.Logger.LogExcInFctCall(exc);
67+
68+
// Log the exception (full parameters)
5069
Log.Logger.LogExcInFctCall(exc, GetType(), MethodBase.GetCurrentMethod(), "My custom exception message!", LogEventLevel.Error);
5170
}
5271
}

src/.idea/.idea.jjm.one.Serilog.Extensions.Logging.Helpers/.idea/.gitignore

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/.idea/.idea.jjm.one.Serilog.Extensions.Logging.Helpers/.idea/.name

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/.idea/.idea.jjm.one.Serilog.Extensions.Logging.Helpers/.idea/encodings.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/.idea/.idea.jjm.one.Serilog.Extensions.Logging.Helpers/.idea/indexLayout.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/.idea/.idea.jjm.one.Serilog.Extensions.Logging.Helpers/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-596 Bytes
Binary file not shown.
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
using System;
2+
using System.Reflection;
3+
using Moq;
4+
using Serilog.Events;
5+
using Serilog;
6+
7+
namespace jjm.one.Serilog.Extensions.Logging.Helpers.Tests.FunctionLogging;
8+
9+
/// <summary>
10+
/// This class contains the tests for the <see cref="FunctionLogging"/> class.
11+
/// </summary>
12+
public class FunctionLoggingTests
13+
{
14+
#region private members
15+
16+
private readonly Mock<ILogger> _logger;
17+
18+
#endregion
19+
20+
#region ctors
21+
22+
/// <summary>
23+
/// The default constructor of the <see cref="FunctionLoggingTests"/> class.
24+
/// </summary>
25+
public FunctionLoggingTests()
26+
{
27+
_logger = new Mock<ILogger>();
28+
}
29+
30+
#endregion
31+
32+
#region tests
33+
34+
/// <summary>
35+
/// 1. test of the LogFctCall function.
36+
/// </summary>
37+
[Fact]
38+
public void LogFctCallTest1()
39+
{
40+
// arrange
41+
_logger.Setup(x => x.Write(LogEventLevel.Debug,
42+
It.IsAny<string>(), It.IsAny<object?[]?>())).Verifiable();
43+
44+
// act
45+
_logger.Object.LogFctCall();
46+
47+
// assert
48+
_logger.Verify(x => x.Write(LogEventLevel.Debug,
49+
"Function called: {ClassName} -> {FctName}",
50+
nameof(FunctionLoggingTests), nameof(LogFctCallTest1)),
51+
Times.Once);
52+
}
53+
54+
/// <summary>
55+
/// 2. test of the LogFctCall function.
56+
/// </summary>
57+
[Fact]
58+
public void LogFctCallTest2()
59+
{
60+
// arrange
61+
_logger.Setup(x => x.Write(LogEventLevel.Debug,
62+
It.IsAny<string>(), It.IsAny<object?[]?>())).Verifiable();
63+
64+
// act
65+
_logger.Object.LogFctCall(GetType(), MethodBase.GetCurrentMethod());
66+
67+
// assert
68+
_logger.Verify(x => x.Write(LogEventLevel.Debug,
69+
"Function called: {ClassName} -> {FctName}",
70+
nameof(FunctionLoggingTests), nameof(LogFctCallTest2)),
71+
Times.Once);
72+
}
73+
74+
/// <summary>
75+
/// 1. test of the LogExcInFctCall function.
76+
/// </summary>
77+
[Fact]
78+
public void LogExcInFctCallTest1()
79+
{
80+
// arrange
81+
var exc = new Exception("Test");
82+
_logger.Setup(x => x.Write(LogEventLevel.Debug, It.IsAny<Exception>(),
83+
It.IsAny<string>(), It.IsAny<object?[]?>())).Verifiable();
84+
85+
// act
86+
_logger.Object.LogExcInFctCall(exc);
87+
88+
// assert
89+
_logger.Verify(x => x.Write(LogEventLevel.Error,
90+
It.Is<Exception>(e => e == exc),
91+
"Exception thrown in: {ClassName} -> {FctName}{CustomMsg}",
92+
nameof(FunctionLoggingTests), nameof(LogExcInFctCallTest1),
93+
string.Empty),
94+
Times.Once);
95+
}
96+
97+
/// <summary>
98+
/// 2. test of the LogExcInFctCall function.
99+
/// </summary>
100+
[Fact]
101+
public void LogExcInFctCallTest2()
102+
{
103+
// arrange
104+
var exc = new Exception("Test");
105+
_logger.Setup(x => x.Write(LogEventLevel.Debug, It.IsAny<Exception>(),
106+
It.IsAny<string>(), It.IsAny<object?[]?>())).Verifiable();
107+
108+
// act
109+
_logger.Object.LogExcInFctCall(exc, "TestMSG");
110+
111+
// assert
112+
_logger.Verify(x => x.Write(LogEventLevel.Error,
113+
It.Is<Exception>(e => e == exc),
114+
"Exception thrown in: {ClassName} -> {FctName}{CustomMsg}",
115+
nameof(FunctionLoggingTests), nameof(LogExcInFctCallTest2),
116+
"\nTestMSG"),
117+
Times.Once);
118+
}
119+
120+
/// <summary>
121+
/// 3. test of the LogExcInFctCall function.
122+
/// </summary>
123+
[Fact]
124+
public void LogExcInFctCallTest3()
125+
{
126+
// arrange
127+
var exc = new Exception("Test");
128+
_logger.Setup(x => x.Write(LogEventLevel.Debug, It.IsAny<Exception>(),
129+
It.IsAny<string>(), It.IsAny<object?[]?>())).Verifiable();
130+
131+
// act
132+
_logger.Object.LogExcInFctCall(exc, GetType(),
133+
MethodBase.GetCurrentMethod());
134+
135+
// assert
136+
_logger.Verify(x => x.Write(LogEventLevel.Error,
137+
It.Is<Exception>(e => e == exc),
138+
"Exception thrown in: {ClassName} -> {FctName}{CustomMsg}",
139+
nameof(FunctionLoggingTests), nameof(LogExcInFctCallTest3),
140+
string.Empty),
141+
Times.Once);
142+
}
143+
144+
/// <summary>
145+
/// 4. test of the LogExcInFctCall function.
146+
/// </summary>
147+
[Fact]
148+
public void LogExcInFctCallTest4()
149+
{
150+
// arrange
151+
var exc = new Exception("Test");
152+
_logger.Setup(x => x.Write(LogEventLevel.Debug, It.IsAny<Exception>(),
153+
It.IsAny<string>(), It.IsAny<object?[]?>())).Verifiable();
154+
155+
// act
156+
_logger.Object.LogExcInFctCall(exc, GetType(),
157+
MethodBase.GetCurrentMethod(), "TestMSG");
158+
159+
// assert
160+
_logger.Verify(x => x.Write(LogEventLevel.Error,
161+
It.Is<Exception>(e => e == exc),
162+
"Exception thrown in: {ClassName} -> {FctName}{CustomMsg}",
163+
nameof(FunctionLoggingTests), nameof(LogExcInFctCallTest4),
164+
"\nTestMSG"),
165+
Times.Once);
166+
}
167+
168+
#endregion
169+
}

0 commit comments

Comments
 (0)