Skip to content

Commit 7247a04

Browse files
authored
Merge pull request #8 from jjm-one/develop
Develop
2 parents fd2342b + a202e17 commit 7247a04

18 files changed

+466
-73
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.Microsoft.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.Microsoft.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.Microsoft.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.Microsoft.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 [Microsoft.Extensions.Logging](https://
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 [Microsoft.Extensions.Logging](https://
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.Microsoft.Extensions.Logging.Helpers/)
2829

30+
### Installing the Nuget Package
31+
32+
| Tool | Command/Code |
33+
|----------------------|--------------|
34+
| Package Manager | ```PM> Install-Package jjm.one.Microsoft.Extensions.Logging.Helpers -Version X.Y.Z``` |
35+
| .NET CLI | ```> dotnet add package jjm.one.Microsoft.Extensions.Logging.Helpers --version X.Y.Z``` |
36+
| PackageReference | ```<PackageReference Include="jjm.one.Microsoft.Extensions.Logging.Helpers" Version="X.Y.Z" />``` |
37+
| Package CLI | ```> paket add jjm.one.Microsoft.Extensions.Logging.Helpers --version X.Y.Z``` |
38+
| Script & Interactive | ```> #r "nuget: jjm.one.Microsoft.Extensions.Logging.Helpers, X.Y.Z"``` |
39+
| Cake as Addin | ```#addin nuget:?package=jjm.one.Microsoft.Extensions.Logging.Helpers&version=X.Y.Z``` |
40+
| Cake as Tool | ```#tool nuget:?package=jjm.one.Microsoft.Extensions.Logging.Helpers&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+
logger.LogFctCall();
55+
56+
// log the function call (full parameters)
4157
logger.LogFctCall(GetType(), MethodBase.GetCurrentMethod(), LogLevel.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+
logger.LogExcInFctCall(exc);
67+
68+
// Log the exception (full parameters)
5069
logger.LogExcInFctCall(exc, GetType(), MethodBase.GetCurrentMethod(), "My custom exception message!", LogLevel.Error);
5170
}
5271
}

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

0 commit comments

Comments
 (0)