-
Notifications
You must be signed in to change notification settings - Fork 838
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move request cancellations to a separate log
- Loading branch information
Showing
6 changed files
with
187 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Yarp.ReverseProxy.Common; | ||
|
||
internal sealed class TestLogger(ILogger xunitLogger, string categoryName) : ILogger | ||
{ | ||
public record LogEntry(string CategoryName, LogLevel LogLevel, EventId EventId, string Message, Exception Exception); | ||
|
||
private static readonly AsyncLocal<List<LogEntry>> _logsAsyncLocal = new(); | ||
|
||
public static List<LogEntry> Collect() => _logsAsyncLocal.Value ??= []; | ||
|
||
public IDisposable BeginScope<TState>(TState state) where TState : notnull => xunitLogger.BeginScope(state); | ||
|
||
public bool IsEnabled(LogLevel logLevel) => true; | ||
|
||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) | ||
{ | ||
_logsAsyncLocal.Value?.Add(new LogEntry(categoryName, logLevel, eventId, formatter(state, exception), exception)); | ||
|
||
xunitLogger.Log(logLevel, eventId, state, exception, formatter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Testing; | ||
using Xunit.Abstractions; | ||
|
||
namespace Yarp.ReverseProxy.Common; | ||
|
||
internal sealed class TestLoggerProvider(ITestOutputHelper output) : ILoggerProvider | ||
{ | ||
private readonly XunitLoggerProvider _xunitLoggerProvider = new(output); | ||
|
||
public ILogger CreateLogger(string categoryName) => new TestLogger(_xunitLoggerProvider.CreateLogger(categoryName), categoryName); | ||
|
||
public void Dispose() => _xunitLoggerProvider.Dispose(); | ||
} |
Oops, something went wrong.