-
Notifications
You must be signed in to change notification settings - Fork 771
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f524eb
commit b2b6e56
Showing
29 changed files
with
364 additions
and
420 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
39 changes: 15 additions & 24 deletions
39
...braries/Microsoft.AspNetCore.Diagnostics.Middleware/Buffering/HttpRequestBufferManager.cs
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 |
---|---|---|
@@ -1,65 +1,56 @@ | ||
// 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 Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Diagnostics.Buffering; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Microsoft.AspNetCore.Diagnostics.Buffering; | ||
|
||
internal sealed class HttpRequestBufferManager : IHttpRequestBufferManager | ||
internal sealed class HttpRequestBufferManager : HttpRequestLogBuffer | ||
{ | ||
private readonly IGlobalBufferManager _globalBufferManager; | ||
private readonly LogBuffer _globalBuffer; | ||
private readonly IHttpContextAccessor _httpContextAccessor; | ||
private readonly IOptionsMonitor<HttpRequestBufferOptions> _requestOptions; | ||
private readonly IOptionsMonitor<GlobalBufferOptions> _globalOptions; | ||
private readonly IOptionsMonitor<HttpRequestLogBufferingOptions> _requestOptions; | ||
private readonly IOptionsMonitor<GlobalLogBufferingOptions> _globalOptions; | ||
|
||
public HttpRequestBufferManager( | ||
IGlobalBufferManager globalBufferManager, | ||
LogBuffer globalBuffer, | ||
IHttpContextAccessor httpContextAccessor, | ||
IOptionsMonitor<HttpRequestBufferOptions> requestOptions, | ||
IOptionsMonitor<GlobalBufferOptions> globalOptions) | ||
IOptionsMonitor<HttpRequestLogBufferingOptions> requestOptions, | ||
IOptionsMonitor<GlobalLogBufferingOptions> globalOptions) | ||
{ | ||
_globalBufferManager = globalBufferManager; | ||
_globalBuffer = globalBuffer; | ||
_httpContextAccessor = httpContextAccessor; | ||
_requestOptions = requestOptions; | ||
_globalOptions = globalOptions; | ||
} | ||
|
||
public void FlushNonRequestLogs() => _globalBufferManager.Flush(); | ||
public override void Flush() => _globalBuffer.Flush(); | ||
|
||
public void FlushCurrentRequestLogs() | ||
public override void FlushCurrentRequestLogs() | ||
{ | ||
_httpContextAccessor.HttpContext?.RequestServices.GetService<HttpRequestBufferHolder>()?.Flush(); | ||
} | ||
|
||
public bool TryEnqueue<TState>( | ||
IBufferedLogger bufferedLogger, | ||
LogLevel logLevel, | ||
string category, | ||
EventId eventId, | ||
TState state, | ||
Exception? exception, | ||
Func<TState, Exception?, string> formatter) | ||
public override bool TryEnqueue<TState>(IBufferedLogger bufferedLogger, in LogEntry<TState> logEntry) | ||
{ | ||
HttpContext? httpContext = _httpContextAccessor.HttpContext; | ||
if (httpContext is null) | ||
{ | ||
return _globalBufferManager.TryEnqueue(bufferedLogger, logLevel, category, eventId, state, exception, formatter); | ||
return _globalBuffer.TryEnqueue(bufferedLogger, logEntry); | ||
} | ||
|
||
HttpRequestBufferHolder? bufferHolder = httpContext.RequestServices.GetService<HttpRequestBufferHolder>(); | ||
ILoggingBuffer? buffer = bufferHolder?.GetOrAdd(category, _ => new HttpRequestBuffer(bufferedLogger, _requestOptions, _globalOptions)!); | ||
ILoggingBuffer? buffer = bufferHolder?.GetOrAdd(logEntry.Category, _ => new HttpRequestBuffer(bufferedLogger, _requestOptions, _globalOptions)!); | ||
|
||
if (buffer is null) | ||
{ | ||
return _globalBufferManager.TryEnqueue(bufferedLogger, logLevel, category, eventId, state, exception, formatter); | ||
return _globalBuffer.TryEnqueue(bufferedLogger, logEntry); | ||
} | ||
|
||
return buffer.TryEnqueue(logLevel, category, eventId, state, exception, formatter); | ||
return buffer.TryEnqueue(logEntry); | ||
} | ||
} |
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
Oops, something went wrong.