Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ indent_style = space
tab_width = 4

# New line preferences
insert_final_newline = true
trim_trailing_whitespace = true


Expand Down Expand Up @@ -67,9 +66,9 @@ dotnet_code_quality_unused_parameters = all:suggestion
#### C# Coding Conventions ####

# var preferences
csharp_style_var_elsewhere = false:silent
csharp_style_var_for_built_in_types = false:silent
csharp_style_var_when_type_is_apparent = false:silent
csharp_style_var_elsewhere = true
csharp_style_var_for_built_in_types = true
csharp_style_var_when_type_is_apparent = true

# Expression-bodied members
csharp_style_expression_bodied_accessors = true:silent
Expand All @@ -89,7 +88,7 @@ csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion

# Modifier preferences
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async
csharp_preferred_modifier_order = public, private, protected, internal, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, volatile, async

# Code-block preferences
csharp_prefer_braces = true:silent
Expand All @@ -103,7 +102,10 @@ csharp_style_unused_value_assignment_preference = discard_variable:suggestion
csharp_style_unused_value_expression_statement_preference = discard_variable:silent

# C# 10
csharp_style_namespace_declarations = file_scoped:warning
csharp_style_namespace_declarations = file_scoped:error
csharp_style_prefer_primary_constructors = true
dotnet_diagnostic.IDE0290.severity = error


#### C# Formatting Rules ####

Expand Down
16 changes: 6 additions & 10 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore source
- name: Build
run: dotnet build --no-restore source
- name: Test
run: dotnet test source /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --logger "GitHubActions;report-warnings=false"
dotnet-version: 9.0.x
- run: dotnet restore source
- run: dotnet build --no-restore source
- run: dotnet test source /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --logger "GitHubActions;report-warnings=false"
19 changes: 7 additions & 12 deletions .github/workflows/PreRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,19 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: echo "ACTIONS_ALLOW_UNSECURE_COMMANDS=true" >> $GITHUB_ENV
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0
- uses: gittools/actions/gitversion/setup@v0
with:
versionSpec: "5.x"
- name: Determine Version
- uses: gittools/actions/gitversion/execute@v0
id: gitversion
uses: gittools/actions/gitversion/execute@v0
with:
useConfigFile: true
- name: Setup .NET
uses: actions/setup-dotnet@v3
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Pack
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
- name: Publish
run: dotnet nuget push ./releases/**/*.nupkg -k=${{ secrets.NUGETORGAPIKEY }} -s=nuget.org
dotnet-version: 9.0.x
- 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
- run: dotnet nuget push ./releases/**/*.nupkg -k=${{ secrets.NUGETORGAPIKEY }} -s=nuget.org
9 changes: 4 additions & 5 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: echo "ACTIONS_ALLOW_UNSECURE_COMMANDS=true" >> $GITHUB_ENV
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0
- uses: gittools/actions/gitversion/setup@v0
with:
versionSpec: "5.x"
- name: Determine Version
Expand All @@ -22,9 +21,9 @@ jobs:
with:
useConfigFile: true
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
dotnet-version: 9.0.x
- name: Pack
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
- name: Publish
Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
# MinimalHttpLogger

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


## Why?
My logs were
* hard to read
* filling up space(*)

My logs were

* hard to read
* filling up space(*)

## What is this?

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:
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:

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


### Change in output

Before:

```log
info: Start processing HTTP request GET https://www.google.com/
info: Sending HTTP request GET https://www.google.com/
Expand All @@ -29,11 +31,11 @@ info: End processing HTTP request after 188.8026ms - 200
```

After:

```log
info: GET https://www.google.com/ - 200 OK in 186.4883ms
```


## Install

```sh
Expand Down
5 changes: 1 addition & 4 deletions samples/With/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using With;

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

await host.RunAsync();



2 changes: 1 addition & 1 deletion samples/With/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"profiles": {
"Without": {
"With": {
"commandName": "Project",
"dotnetRunMessages": true,
"environmentVariables": {
Expand Down
10 changes: 5 additions & 5 deletions samples/With/With.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0"/>
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\source\MinimalHttpLogger\MinimalHttpLogger.csproj" />
<ProjectReference Include="..\..\source\MinimalHttpLogger\MinimalHttpLogger.csproj"/>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion samples/With/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_logger.LogInformation("Timeout!");
}
catch(Exception e)
catch (Exception e)
{
_logger.LogError(e.Message);
}
Expand Down
10 changes: 5 additions & 5 deletions samples/Without/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Without;

IHost host = Host.CreateDefaultBuilder(args)
.ConfigureLogging((c, b) =>
AppContext.SetSwitch("System.Net.Http.DisableUriRedaction", true);

var host = Host.CreateDefaultBuilder(args)
.ConfigureLogging((_, b) =>
{
b.AddSimpleConsole(o => { o.SingleLine = true; });
})
Expand All @@ -12,11 +14,9 @@
hostOptions.BackgroundServiceExceptionBehavior = BackgroundServiceExceptionBehavior.Ignore;
});
services.AddHttpClient();

services.AddHostedService<Worker>();
})
.Build();

await host.RunAsync();



8 changes: 4 additions & 4 deletions samples/Without/Without.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0"/>
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0"/>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion samples/Without/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_logger.LogInformation("Timeout!");
}
catch(Exception e)
catch (Exception e)
{
_logger.LogError(e.Message);
}
Expand Down
Loading