Skip to content

Commit 136a54c

Browse files
authored
.NET 9 (#8)
+semver:major
1 parent 93d70f7 commit 136a54c

14 files changed

Lines changed: 99 additions & 112 deletions

File tree

.editorconfig

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ indent_style = space
1616
tab_width = 4
1717

1818
# New line preferences
19-
insert_final_newline = true
2019
trim_trailing_whitespace = true
2120

2221

@@ -67,9 +66,9 @@ dotnet_code_quality_unused_parameters = all:suggestion
6766
#### C# Coding Conventions ####
6867

6968
# var preferences
70-
csharp_style_var_elsewhere = false:silent
71-
csharp_style_var_for_built_in_types = false:silent
72-
csharp_style_var_when_type_is_apparent = false:silent
69+
csharp_style_var_elsewhere = true
70+
csharp_style_var_for_built_in_types = true
71+
csharp_style_var_when_type_is_apparent = true
7372

7473
# Expression-bodied members
7574
csharp_style_expression_bodied_accessors = true:silent
@@ -89,7 +88,7 @@ csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
8988
csharp_style_conditional_delegate_call = true:suggestion
9089

9190
# Modifier preferences
92-
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async
91+
csharp_preferred_modifier_order = public, private, protected, internal, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, volatile, async
9392

9493
# Code-block preferences
9594
csharp_prefer_braces = true:silent
@@ -103,7 +102,10 @@ csharp_style_unused_value_assignment_preference = discard_variable:suggestion
103102
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
104103

105104
# C# 10
106-
csharp_style_namespace_declarations = file_scoped:warning
105+
csharp_style_namespace_declarations = file_scoped:error
106+
csharp_style_prefer_primary_constructors = true
107+
dotnet_diagnostic.IDE0290.severity = error
108+
107109

108110
#### C# Formatting Rules ####
109111

.github/workflows/CI.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v3
11-
- name: Setup .NET
12-
uses: actions/setup-dotnet@v3
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-dotnet@v4
1312
with:
14-
dotnet-version: 8.0.x
15-
- name: Restore dependencies
16-
run: dotnet restore source
17-
- name: Build
18-
run: dotnet build --no-restore source
19-
- name: Test
20-
run: dotnet test source /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --logger "GitHubActions;report-warnings=false"
13+
dotnet-version: 9.0.x
14+
- run: dotnet restore source
15+
- run: dotnet build --no-restore source
16+
- run: dotnet test source /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --logger "GitHubActions;report-warnings=false"

.github/workflows/PreRelease.yml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,19 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v3
11+
- uses: actions/checkout@v4
1212
with:
1313
fetch-depth: 0
1414
- run: echo "ACTIONS_ALLOW_UNSECURE_COMMANDS=true" >> $GITHUB_ENV
15-
- name: Install GitVersion
16-
uses: gittools/actions/gitversion/setup@v0
15+
- uses: gittools/actions/gitversion/setup@v0
1716
with:
1817
versionSpec: "5.x"
19-
- name: Determine Version
18+
- uses: gittools/actions/gitversion/execute@v0
2019
id: gitversion
21-
uses: gittools/actions/gitversion/execute@v0
2220
with:
2321
useConfigFile: true
24-
- name: Setup .NET
25-
uses: actions/setup-dotnet@v3
22+
- uses: actions/setup-dotnet@v4
2623
with:
27-
dotnet-version: 8.0.x
28-
- name: Pack
29-
run: dotnet pack source /p:Version=${{ steps.gitversion.outputs.NuGetVersionV2 }}-${{ steps.gitversion.outputs.ShortSha }} /p:InformationalVersion=${{ steps.gitversion.outputs.informationalVersion }} /p:PackageReleaseNotes="https://github.com/$GITHUB_REPOSITORY/releases/tag/${{ steps.gitversion.outputs.NuGetVersionV2 }}" -o ./releases
30-
- name: Publish
31-
run: dotnet nuget push ./releases/**/*.nupkg -k=${{ secrets.NUGETORGAPIKEY }} -s=nuget.org
24+
dotnet-version: 9.0.x
25+
- run: dotnet pack source /p:Version=${{ steps.gitversion.outputs.NuGetVersionV2 }}-${{ steps.gitversion.outputs.ShortSha }} /p:InformationalVersion=${{ steps.gitversion.outputs.informationalVersion }} /p:PackageReleaseNotes="https://github.com/$GITHUB_REPOSITORY/releases/tag/${{ steps.gitversion.outputs.NuGetVersionV2 }}" -o ./releases
26+
- run: dotnet nuget push ./releases/**/*.nupkg -k=${{ secrets.NUGETORGAPIKEY }} -s=nuget.org

.github/workflows/Release.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v3
11+
- uses: actions/checkout@v4
1212
with:
1313
fetch-depth: 0
1414
- run: echo "ACTIONS_ALLOW_UNSECURE_COMMANDS=true" >> $GITHUB_ENV
15-
- name: Install GitVersion
16-
uses: gittools/actions/gitversion/setup@v0
15+
- uses: gittools/actions/gitversion/setup@v0
1716
with:
1817
versionSpec: "5.x"
1918
- name: Determine Version
@@ -22,9 +21,9 @@ jobs:
2221
with:
2322
useConfigFile: true
2423
- name: Setup .NET
25-
uses: actions/setup-dotnet@v3
24+
uses: actions/setup-dotnet@v4
2625
with:
27-
dotnet-version: 8.0.x
26+
dotnet-version: 9.0.x
2827
- name: Pack
2928
run: dotnet pack source /p:Version=${{ steps.gitversion.outputs.majorMinorPatch }} /p:InformationalVersion=${{ steps.gitversion.outputs.informationalVersion }} /p:PackageReleaseNotes="https://github.com/$GITHUB_REPOSITORY/releases/tag/${{ steps.gitversion.outputs.majorMinorPatch }}" -o ./releases
3029
- name: Publish

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
# MinimalHttpLogger
22

33
[![Build](https://github.com/johnkors/MinimalHttpLogger/workflows/CI/badge.svg)](https://github.com/johnkors/MinimalHttpLogger/actions)
4-
[![NuGet](https://img.shields.io/nuget/v/MinimalHttpLogger.svg)](https://www.nuget.org/packages/MinimalHttpLogger/)
4+
[![NuGet](https://img.shields.io/nuget/v/MinimalHttpLogger.svg)](https://www.nuget.org/packages/MinimalHttpLogger/)
55
[![NuGet](https://img.shields.io/nuget/dt/MinimalHttpLogger.svg)](https://www.nuget.org/packages/MinimalHttpLogger/)
66

7-
87
## Why?
9-
My logs were
10-
* hard to read
11-
* filling up space(*)
8+
9+
My logs were
10+
11+
* hard to read
12+
* filling up space(*)
1213

1314
## What is this?
1415

15-
It's not possible to configure the log pattern of the Microsoft.Extensions.Http based HttpClient loggers. To modify, one has to replace them. This package replaces the default loggers with a logger that:
16+
It's not possible to configure the log pattern of the Microsoft.Extensions.Http based HttpClient loggers. To modify, one
17+
has to replace them. This package replaces the default loggers with a logger that:
1618

17-
1. Reduces the number of log statements on httpclient requests from 4 to 1
19+
1. Reduces the number of log statements on httpclient requests from 4 to 1
1820
2. Logs 1 aggregated log statement: `{Method} {Uri} - {StatusCode} {StatusCodeLiteral} in {Time}ms`
1921

20-
2122
### Change in output
2223

2324
Before:
25+
2426
```log
2527
info: Start processing HTTP request GET https://www.google.com/
2628
info: Sending HTTP request GET https://www.google.com/
@@ -29,11 +31,11 @@ info: End processing HTTP request after 188.8026ms - 200
2931
```
3032

3133
After:
34+
3235
```log
3336
info: GET https://www.google.com/ - 200 OK in 186.4883ms
3437
```
3538

36-
3739
## Install
3840

3941
```sh

samples/With/Program.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using With;
22

3-
IHost host = Host.CreateDefaultBuilder(args)
3+
var host = Host.CreateDefaultBuilder(args)
44
.ConfigureLogging((c, b) =>
55
{
66
b.AddSimpleConsole(o => { o.SingleLine = true; });
@@ -18,6 +18,3 @@
1818
.Build();
1919

2020
await host.RunAsync();
21-
22-
23-

samples/With/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"profiles": {
3-
"Without": {
3+
"With": {
44
"commandName": "Project",
55
"dotnetRunMessages": true,
66
"environmentVariables": {

samples/With/With.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<Project Sdk="Microsoft.NET.Sdk.Worker">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
10-
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
11-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
9+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0"/>
10+
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0"/>
11+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0"/>
1212
</ItemGroup>
1313

1414
<ItemGroup>
15-
<ProjectReference Include="..\..\source\MinimalHttpLogger\MinimalHttpLogger.csproj" />
15+
<ProjectReference Include="..\..\source\MinimalHttpLogger\MinimalHttpLogger.csproj"/>
1616
</ItemGroup>
1717
</Project>

samples/With/Worker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
2424
{
2525
_logger.LogInformation("Timeout!");
2626
}
27-
catch(Exception e)
27+
catch (Exception e)
2828
{
2929
_logger.LogError(e.Message);
3030
}

samples/Without/Program.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using Without;
22

3-
IHost host = Host.CreateDefaultBuilder(args)
4-
.ConfigureLogging((c, b) =>
3+
AppContext.SetSwitch("System.Net.Http.DisableUriRedaction", true);
4+
5+
var host = Host.CreateDefaultBuilder(args)
6+
.ConfigureLogging((_, b) =>
57
{
68
b.AddSimpleConsole(o => { o.SingleLine = true; });
79
})
@@ -12,11 +14,9 @@
1214
hostOptions.BackgroundServiceExceptionBehavior = BackgroundServiceExceptionBehavior.Ignore;
1315
});
1416
services.AddHttpClient();
17+
1518
services.AddHostedService<Worker>();
1619
})
1720
.Build();
1821

1922
await host.RunAsync();
20-
21-
22-

0 commit comments

Comments
 (0)