Skip to content

Commit 25c59ac

Browse files
Fixes printing log messages outside of the request scope. Closes #1205 (#1209)
1 parent 8d7fd61 commit 25c59ac

File tree

2 files changed

+235
-159
lines changed

2 files changed

+235
-159
lines changed

dev-proxy/Logging/LogEntry.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Microsoft.Extensions.Logging.Abstractions;
6+
7+
namespace DevProxy.Logging;
8+
9+
readonly struct LogEntry
10+
{
11+
public LogLevel LogLevel { get; init; }
12+
public string Category { get; init; }
13+
public EventId EventId { get; init; }
14+
public string? Message { get; init; }
15+
public Exception? Exception { get; init; }
16+
17+
public static LogEntry FromLogEntry<TState>(LogEntry<TState> logEntry)
18+
{
19+
return new()
20+
{
21+
LogLevel = logEntry.LogLevel,
22+
Category = logEntry.Category,
23+
EventId = logEntry.EventId,
24+
Message = logEntry.Formatter(logEntry.State, logEntry.Exception),
25+
Exception = logEntry.Exception
26+
};
27+
}
28+
}

0 commit comments

Comments
 (0)