Skip to content

Commit 2247afc

Browse files
authored
Merge pull request #192 from nanotaboada/feature/serilog
refactor: replace Microsoft.Extensions.Logging with Serilog
2 parents d809aa0 + a63fcaf commit 2247afc

File tree

11 files changed

+508
-65
lines changed

11 files changed

+508
-65
lines changed

.github/workflows/codacy.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,29 @@ on:
1717
schedule:
1818
- cron: '0 21 * * 5' # Runs at 21:00, only on Friday
1919

20-
permissions:
21-
contents: read
22-
2320
jobs:
2421
codacy-security-scan:
25-
permissions:
26-
contents: read
27-
security-events: write
28-
actions: read
2922
name: Codacy Security Scan
3023
runs-on: ubuntu-latest
3124
steps:
3225
- name: Checkout code
33-
uses: actions/checkout@v4
34-
# Execute Codacy Analysis CLI and generate a SARIF output with the security
35-
# issues identified during the analysis
26+
uses: actions/checkout@main
27+
3628
- name: Run Codacy Analysis CLI
3729
uses: codacy/codacy-analysis-cli-action@master
3830
with:
3931
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
4032
verbose: true
4133
output: results.sarif
4234
format: sarif
35+
# Adjust severity of non-security issues
4336
gh-code-scanning-compat: true
37+
# Force 0 exit code to allow SARIF file generation
38+
# This will hand over control about PR rejection to the GitHub side
4439
max-allowed-issues: 2147483647
40+
4541
# Upload the SARIF file generated in the previous step
4642
- name: Upload SARIF results file
47-
uses: github/codeql-action/upload-sarif@v3
43+
uses: github/codeql-action/upload-sarif@main
4844
with:
4945
sarif_file: results.sarif

Dotnet.Samples.AspNetCore.WebApi.Tests/Unit/PlayerServiceTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public async Task GivenRetrieveAsync_WhenExecutedForTheSecondTime_ThenSecondExec
7070
// Arrange
7171
var players = PlayerFakes.CreateStarting11();
7272
var (repository, logger, memoryCache) = PlayerMocks.SetupServiceMocks(cacheValue: players);
73+
repository.Setup(repository => repository.GetAllAsync()).ReturnsAsync(players);
7374
var value = It.IsAny<object>();
7475

7576
var service = new PlayerService(repository.Object, logger.Object, memoryCache.Object);

Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/PlayerMocks.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,34 @@ public static Mock<ILogger<T>> LoggerMock<T>()
3636

3737
public static Mock<IMemoryCache> MemoryCacheMock(object? value)
3838
{
39-
var fromCache = false;
39+
var cachedValue = false;
4040
var mock = new Mock<IMemoryCache>();
41-
mock.Setup(cache => cache.TryGetValue(It.IsAny<object>(), out value))
41+
42+
mock.Setup(cache => cache.TryGetValue(It.IsAny<object>(), out It.Ref<object>.IsAny!))
43+
.Callback(
44+
new TryGetValueDelegate(
45+
(object _, out object? output) =>
46+
{
47+
output = cachedValue ? value : null;
48+
}
49+
)
50+
)
4251
.Returns(() =>
4352
{
44-
bool hasValue = fromCache;
45-
fromCache = true; // Subsequent invocations will return true
53+
bool hasValue = cachedValue;
54+
cachedValue = true; // Subsequent invocations will return true
4655
return hasValue;
4756
});
57+
4858
mock.Setup(cache => cache.CreateEntry(It.IsAny<object>()))
4959
.Returns(Mock.Of<ICacheEntry>);
5060
mock.Setup(cache => cache.Remove(It.IsAny<object>()));
5161

5262
return mock;
5363
}
5464

65+
private delegate void TryGetValueDelegate(object key, out object? value);
66+
5567
public static Mock<IUrlHelper> UrlHelperMock()
5668
{
5769
var mock = new Mock<IUrlHelper>();

Dotnet.Samples.AspNetCore.WebApi.Tests/packages.lock.json

Lines changed: 186 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,15 @@
850850
"Microsoft.Extensions.Primitives": "9.0.3"
851851
}
852852
},
853+
"Microsoft.Extensions.Configuration": {
854+
"type": "Transitive",
855+
"resolved": "9.0.3",
856+
"contentHash": "RIEeZxWYm77+OWLwgik7DzSVSONjqkmcbuCb1koZdGAV7BgOUWnLz80VMyHZMw3onrVwFCCMHBBdruBPuQTvkg==",
857+
"dependencies": {
858+
"Microsoft.Extensions.Configuration.Abstractions": "9.0.3",
859+
"Microsoft.Extensions.Primitives": "9.0.3"
860+
}
861+
},
853862
"Microsoft.Extensions.Configuration.Abstractions": {
854863
"type": "Transitive",
855864
"resolved": "9.0.3",
@@ -858,6 +867,38 @@
858867
"Microsoft.Extensions.Primitives": "9.0.3"
859868
}
860869
},
870+
"Microsoft.Extensions.Configuration.Binder": {
871+
"type": "Transitive",
872+
"resolved": "9.0.0",
873+
"contentHash": "RiScL99DcyngY9zJA2ROrri7Br8tn5N4hP4YNvGdTN/bvg1A3dwvDOxHnNZ3Im7x2SJ5i4LkX1uPiR/MfSFBLQ==",
874+
"dependencies": {
875+
"Microsoft.Extensions.Configuration.Abstractions": "9.0.0"
876+
}
877+
},
878+
"Microsoft.Extensions.Configuration.FileExtensions": {
879+
"type": "Transitive",
880+
"resolved": "9.0.3",
881+
"contentHash": "tBNMSDJ2q7WQK2zwPhHY5I/q95t7sf6dT079mGrNm0yOZF/gM9JvR/LtCb/rwhRmh7A6XMnzv5WbpCh9KLq9EQ==",
882+
"dependencies": {
883+
"Microsoft.Extensions.Configuration": "9.0.3",
884+
"Microsoft.Extensions.Configuration.Abstractions": "9.0.3",
885+
"Microsoft.Extensions.FileProviders.Abstractions": "9.0.3",
886+
"Microsoft.Extensions.FileProviders.Physical": "9.0.3",
887+
"Microsoft.Extensions.Primitives": "9.0.3"
888+
}
889+
},
890+
"Microsoft.Extensions.Configuration.Json": {
891+
"type": "Transitive",
892+
"resolved": "9.0.3",
893+
"contentHash": "mjkp3ZwynNacZk4uq93I0DyCY48FZmi3yRV0xlfeDuWh44KcDunPXHwt8IWr4kL7cVM6eiFVe6YTJg97KzUAUA==",
894+
"dependencies": {
895+
"Microsoft.Extensions.Configuration": "9.0.3",
896+
"Microsoft.Extensions.Configuration.Abstractions": "9.0.3",
897+
"Microsoft.Extensions.Configuration.FileExtensions": "9.0.3",
898+
"Microsoft.Extensions.FileProviders.Abstractions": "9.0.3",
899+
"System.Text.Json": "9.0.3"
900+
}
901+
},
861902
"Microsoft.Extensions.DependencyInjection": {
862903
"type": "Transitive",
863904
"resolved": "9.0.3",
@@ -880,6 +921,51 @@
880921
"System.Text.Json": "9.0.3"
881922
}
882923
},
924+
"Microsoft.Extensions.Diagnostics.Abstractions": {
925+
"type": "Transitive",
926+
"resolved": "9.0.0",
927+
"contentHash": "1K8P7XzuzX8W8pmXcZjcrqS6x5eSSdvhQohmcpgiQNY/HlDAlnrhR9dvlURfFz428A+RTCJpUyB+aKTA6AgVcQ==",
928+
"dependencies": {
929+
"Microsoft.Extensions.DependencyInjection.Abstractions": "9.0.0",
930+
"Microsoft.Extensions.Options": "9.0.0",
931+
"System.Diagnostics.DiagnosticSource": "9.0.0"
932+
}
933+
},
934+
"Microsoft.Extensions.FileProviders.Abstractions": {
935+
"type": "Transitive",
936+
"resolved": "9.0.3",
937+
"contentHash": "umczZ3+QPpzlrW/lkvy+IB0p52+qZ5w++aqx2lTCMOaPKzwcbVdrJgiQ3ajw5QWBp7gChLUiCYkSlWUpfjv24g==",
938+
"dependencies": {
939+
"Microsoft.Extensions.Primitives": "9.0.3"
940+
}
941+
},
942+
"Microsoft.Extensions.FileProviders.Physical": {
943+
"type": "Transitive",
944+
"resolved": "9.0.3",
945+
"contentHash": "th2+tQBV5oWjgKhip9GjiIv2AEK3QvfAO3tZcqV3F3dEt5D6Gb411RntCj1+8GS9HaRRSxjSGx/fCrMqIjkb1Q==",
946+
"dependencies": {
947+
"Microsoft.Extensions.FileProviders.Abstractions": "9.0.3",
948+
"Microsoft.Extensions.FileSystemGlobbing": "9.0.3",
949+
"Microsoft.Extensions.Primitives": "9.0.3"
950+
}
951+
},
952+
"Microsoft.Extensions.FileSystemGlobbing": {
953+
"type": "Transitive",
954+
"resolved": "9.0.3",
955+
"contentHash": "Rec77KHk4iNpFznHi5/6wF3MlUDcKqg26t8gRYbUm1PSukZ4B6mrXpZsJSNOiwyhhQVkjYbaoZxi5XJgRQ5lFg=="
956+
},
957+
"Microsoft.Extensions.Hosting.Abstractions": {
958+
"type": "Transitive",
959+
"resolved": "9.0.0",
960+
"contentHash": "yUKJgu81ExjvqbNWqZKshBbLntZMbMVz/P7Way2SBx7bMqA08Mfdc9O7hWDKAiSp+zPUGT6LKcSCQIPeDK+CCw==",
961+
"dependencies": {
962+
"Microsoft.Extensions.Configuration.Abstractions": "9.0.0",
963+
"Microsoft.Extensions.DependencyInjection.Abstractions": "9.0.0",
964+
"Microsoft.Extensions.Diagnostics.Abstractions": "9.0.0",
965+
"Microsoft.Extensions.FileProviders.Abstractions": "9.0.0",
966+
"Microsoft.Extensions.Logging.Abstractions": "9.0.0"
967+
}
968+
},
883969
"Microsoft.Extensions.Logging": {
884970
"type": "Transitive",
885971
"resolved": "9.0.3",
@@ -1292,6 +1378,88 @@
12921378
"resolved": "6.11.0",
12931379
"contentHash": "v/GGlIj2dd7svplFmASWEueu62veKW0MrMtBaZ7QG8aJTSGv2yE+pgUGhXRcQ4nxNOEq/wLBrz1vkth/1SND7A=="
12941380
},
1381+
"Serilog": {
1382+
"type": "Transitive",
1383+
"resolved": "4.2.0",
1384+
"contentHash": "gmoWVOvKgbME8TYR+gwMf7osROiWAURterc6Rt2dQyX7wtjZYpqFiA/pY6ztjGQKKV62GGCyOcmtP1UKMHgSmA=="
1385+
},
1386+
"Serilog.AspNetCore": {
1387+
"type": "Transitive",
1388+
"resolved": "9.0.0",
1389+
"contentHash": "JslDajPlBsn3Pww1554flJFTqROvK9zz9jONNQgn0D8Lx2Trw8L0A8/n6zEQK1DAZWXrJwiVLw8cnTR3YFuYsg==",
1390+
"dependencies": {
1391+
"Serilog": "4.2.0",
1392+
"Serilog.Extensions.Hosting": "9.0.0",
1393+
"Serilog.Formatting.Compact": "3.0.0",
1394+
"Serilog.Settings.Configuration": "9.0.0",
1395+
"Serilog.Sinks.Console": "6.0.0",
1396+
"Serilog.Sinks.Debug": "3.0.0",
1397+
"Serilog.Sinks.File": "6.0.0"
1398+
}
1399+
},
1400+
"Serilog.Extensions.Hosting": {
1401+
"type": "Transitive",
1402+
"resolved": "9.0.0",
1403+
"contentHash": "u2TRxuxbjvTAldQn7uaAwePkWxTHIqlgjelekBtilAGL5sYyF3+65NWctN4UrwwGLsDC7c3Vz3HnOlu+PcoxXg==",
1404+
"dependencies": {
1405+
"Microsoft.Extensions.DependencyInjection.Abstractions": "9.0.0",
1406+
"Microsoft.Extensions.Hosting.Abstractions": "9.0.0",
1407+
"Microsoft.Extensions.Logging.Abstractions": "9.0.0",
1408+
"Serilog": "4.2.0",
1409+
"Serilog.Extensions.Logging": "9.0.0"
1410+
}
1411+
},
1412+
"Serilog.Extensions.Logging": {
1413+
"type": "Transitive",
1414+
"resolved": "9.0.0",
1415+
"contentHash": "NwSSYqPJeKNzl5AuXVHpGbr6PkZJFlNa14CdIebVjK3k/76kYj/mz5kiTRNVSsSaxM8kAIa1kpy/qyT9E4npRQ==",
1416+
"dependencies": {
1417+
"Microsoft.Extensions.Logging": "9.0.0",
1418+
"Serilog": "4.2.0"
1419+
}
1420+
},
1421+
"Serilog.Formatting.Compact": {
1422+
"type": "Transitive",
1423+
"resolved": "3.0.0",
1424+
"contentHash": "wQsv14w9cqlfB5FX2MZpNsTawckN4a8dryuNGbebB/3Nh1pXnROHZov3swtu3Nj5oNG7Ba+xdu7Et/ulAUPanQ==",
1425+
"dependencies": {
1426+
"Serilog": "4.0.0"
1427+
}
1428+
},
1429+
"Serilog.Settings.Configuration": {
1430+
"type": "Transitive",
1431+
"resolved": "9.0.0",
1432+
"contentHash": "4/Et4Cqwa+F88l5SeFeNZ4c4Z6dEAIKbu3MaQb2Zz9F/g27T5a3wvfMcmCOaAiACjfUb4A6wrlTVfyYUZk3RRQ==",
1433+
"dependencies": {
1434+
"Microsoft.Extensions.Configuration.Binder": "9.0.0",
1435+
"Microsoft.Extensions.DependencyModel": "9.0.0",
1436+
"Serilog": "4.2.0"
1437+
}
1438+
},
1439+
"Serilog.Sinks.Console": {
1440+
"type": "Transitive",
1441+
"resolved": "6.0.0",
1442+
"contentHash": "fQGWqVMClCP2yEyTXPIinSr5c+CBGUvBybPxjAGcf7ctDhadFhrQw03Mv8rJ07/wR5PDfFjewf2LimvXCDzpbA==",
1443+
"dependencies": {
1444+
"Serilog": "4.0.0"
1445+
}
1446+
},
1447+
"Serilog.Sinks.Debug": {
1448+
"type": "Transitive",
1449+
"resolved": "3.0.0",
1450+
"contentHash": "4BzXcdrgRX7wde9PmHuYd9U6YqycCC28hhpKonK7hx0wb19eiuRj16fPcPSVp0o/Y1ipJuNLYQ00R3q2Zs8FDA==",
1451+
"dependencies": {
1452+
"Serilog": "4.0.0"
1453+
}
1454+
},
1455+
"Serilog.Sinks.File": {
1456+
"type": "Transitive",
1457+
"resolved": "6.0.0",
1458+
"contentHash": "lxjg89Y8gJMmFxVkbZ+qDgjl+T4yC5F7WSLTvA+5q0R04tfKVLRL/EHpYoJ/MEQd2EeCKDuylBIVnAYMotmh2A==",
1459+
"dependencies": {
1460+
"Serilog": "4.0.0"
1461+
}
1462+
},
12951463
"SQLitePCLRaw.bundle_e_sqlite3": {
12961464
"type": "Transitive",
12971465
"resolved": "2.1.10",
@@ -1324,35 +1492,35 @@
13241492
},
13251493
"Swashbuckle.AspNetCore": {
13261494
"type": "Transitive",
1327-
"resolved": "8.0.0",
1328-
"contentHash": "K9FzGTxmwfD+7sVf/FTq/TZFHBTXcROgdcg7gLFwKwgvXwaqTtjGVdam27j0kYfgZZyWlOKr+abmtyd2nAd5eA==",
1495+
"resolved": "8.1.0",
1496+
"contentHash": "8NJwXskWNBhX4IntitP1VP68hzhQ9Sex4mR9ZbqCuuUsaWlfrMA+yDIYDFsbHlB2NQ6Gt27AT15BWo9jxHj1tg==",
13291497
"dependencies": {
13301498
"Microsoft.Extensions.ApiDescription.Server": "6.0.5",
1331-
"Swashbuckle.AspNetCore.Swagger": "8.0.0",
1332-
"Swashbuckle.AspNetCore.SwaggerGen": "8.0.0",
1333-
"Swashbuckle.AspNetCore.SwaggerUI": "8.0.0"
1499+
"Swashbuckle.AspNetCore.Swagger": "8.1.0",
1500+
"Swashbuckle.AspNetCore.SwaggerGen": "8.1.0",
1501+
"Swashbuckle.AspNetCore.SwaggerUI": "8.1.0"
13341502
}
13351503
},
13361504
"Swashbuckle.AspNetCore.Swagger": {
13371505
"type": "Transitive",
1338-
"resolved": "8.0.0",
1339-
"contentHash": "+8Y4pVTWbnzotIk6d6rcwsHGpCchPDqqrvYkyGlI3go+pFaKM+4eX30iCyI0hvr0RMtObJCFhK6aDtlQFbEF1g==",
1506+
"resolved": "8.1.0",
1507+
"contentHash": "TRpBDdWh/6IzXHOLKVEuZSuhcdc8OIwhr8dyLnWvEh6FO4f0KiATAzr8yzHspcCFzCc/CONpvUCq4DzazpP6Og==",
13401508
"dependencies": {
13411509
"Microsoft.OpenApi": "1.6.23"
13421510
}
13431511
},
13441512
"Swashbuckle.AspNetCore.SwaggerGen": {
13451513
"type": "Transitive",
1346-
"resolved": "8.0.0",
1347-
"contentHash": "skCeIQ93yMcUm1PQby5qitFM6KLIlLMj4/i8JHy86x2OFzxTNaaas2kUg6rNV3JvucFvYCNyImg7NMtZHErSzQ==",
1514+
"resolved": "8.1.0",
1515+
"contentHash": "sXAUNodmnzrJb1qmgdLY6HgTDsgagXCn6p+qygW2wP0BjcvdZZA6GdDgtuc8iQON9ekrp7m5G0Zc09lvuNhc/A==",
13481516
"dependencies": {
1349-
"Swashbuckle.AspNetCore.Swagger": "8.0.0"
1517+
"Swashbuckle.AspNetCore.Swagger": "8.1.0"
13501518
}
13511519
},
13521520
"Swashbuckle.AspNetCore.SwaggerUI": {
13531521
"type": "Transitive",
1354-
"resolved": "8.0.0",
1355-
"contentHash": "IMqmgclFiZL2QIfopOmWYofZzckrl+SdMt1h4mKC0jc94F+uzt3IHA3YFC0CGlwBqTTSnxHqNUKomNTeAhZbYA=="
1522+
"resolved": "8.1.0",
1523+
"contentHash": "PYyTbYrEz1q8N8ZpCFzY5hOkvP5gv9oIml06wrrrjGRFvVXyCF/b58FRI/9mnRKRBAmWKZR5pqhmJBzvsVveSQ=="
13561524
},
13571525
"System.ClientModel": {
13581526
"type": "Transitive",
@@ -1642,8 +1810,13 @@
16421810
"Microsoft.EntityFrameworkCore.InMemory": "[9.0.3, )",
16431811
"Microsoft.EntityFrameworkCore.SqlServer": "[9.0.3, )",
16441812
"Microsoft.EntityFrameworkCore.Sqlite": "[9.0.3, )",
1813+
"Microsoft.Extensions.Configuration.Json": "[9.0.3, )",
16451814
"Microsoft.VisualStudio.Web.CodeGeneration.Design": "[9.0.0, )",
1646-
"Swashbuckle.AspNetCore": "[8.0.0, )"
1815+
"Serilog.AspNetCore": "[9.0.0, )",
1816+
"Serilog.Settings.Configuration": "[9.0.0, )",
1817+
"Serilog.Sinks.Console": "[6.0.0, )",
1818+
"Serilog.Sinks.File": "[6.0.0, )",
1819+
"Swashbuckle.AspNetCore": "[8.1.0, )"
16471820
}
16481821
}
16491822
}

Dotnet.Samples.AspNetCore.WebApi/Dotnet.Samples.AspNetCore.WebApi.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.3" />
1112
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" />
1213
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.3">
1314
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -17,6 +18,10 @@
1718
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.3" />
1819
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.3" />
1920
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.14" />
21+
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
22+
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />
23+
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
24+
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
2025
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.0" />
2126
</ItemGroup>
2227

0 commit comments

Comments
 (0)