Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce IBufferedLogger #103138

Merged
merged 7 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,21 @@
public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) { throw null; }
public void Log<TState>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, TState state, System.Exception? exception, System.Func<TState, System.Exception?, string> formatter) { }
}
public abstract class BufferedLogRecord
{
public abstract System.DateTimeOffset Timestamp { get; }
public abstract Microsoft.Extensions.Logging.LogLevel LogLevel { get; }
public abstract Microsoft.Extensions.Logging.EventId EventId { get; }
public virtual string? Exception { get; }
public virtual System.Diagnostics.ActivitySpanId? ActivitySpanId { get; }
public virtual System.Diagnostics.ActivityTraceId? ActivityTraceId { get; }
public virtual int? ManagedThreadId { get; }
public virtual string? FormattedMessage { get; }
public virtual string? MessageTemplate { get; }
public virtual System.Collections.Generic.IReadOnlyList<System.Collections.Generic.KeyValuePair<string, object?>> Attributes { get; }
}
public interface IBufferedLogger
{
void LogRecords(System.Collections.Generic.IEnumerable<Microsoft.Extensions.Logging.BufferedLogRecord> records);

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build wasi-wasm linux Release LibraryTests_Smoke_AOT)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm Debug AllSubsets_Mono)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-riscv64 Release AllSubsets_Mono)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build wasi-wasm linux Release LibraryTests_Smoke)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-x64 Release AllSubsets_Mono)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug AllSubsets_Mono_LLVMJIT)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug AllSubsets_Mono_LLVMJIT)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build android-arm64 Release AllSubsets_Mono)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Release AllSubsets_Mono_LLVMAOT)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build android-arm Release AllSubsets_Mono)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_Interpreter_LibrariesTests)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Release AllSubsets_Mono_LLVMAOT)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build ios-arm64 Release AllSubsets_Mono)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Release NativeAOT_Libraries)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug AllSubsets_Mono_LLVMAOT)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-arm64 Release NativeAOT_Libraries)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Release AllSubsets_Mono_LLVMJIT)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build tvossimulator-x64 Debug AllSubsets_Mono)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build maccatalyst-x64 Release AllSubsets_Mono)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests_Smoke_AOT)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / dotnet-linker-tests (Build browser-wasm linux release Runtime_Release)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests_EAT)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests_Threading)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build tvos-arm64 Release AllSubsets_Mono)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm Debug AllSubsets_CoreCLR_ReleaseRuntimeLibs)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug CoreCLR_Libraries)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / dotnet-linker-tests (Build osx-x64 release Runtime_Release)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-arm64 Debug AllSubsets_CoreCLR_ReleaseRuntimeLibs)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build tvos-arm64 Release AllSubsets_NativeAOT)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-x64 Debug CoreCLR_Libraries)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-x64 Debug AllSubsets_CoreCLR)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug AllSubsets_CoreCLR)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build ios-arm64 Release AllSubsets_NativeAOT)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Libraries_CheckedCoreCLR)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / dotnet-linker-tests (Build linux-x64 release Runtime_Release)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug CoreCLR_Libraries)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Libraries_CheckedCoreCLR)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-arm64 Debug AllSubsets_CoreCLR)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / dotnet-linker-tests

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / dotnet-linker-tests

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / dotnet-linker-tests

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop (Build linux-x64 debug Libraries_AllConfigurations)

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)

Check failure on line 220 in src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs#L220

src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs(220,93): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'BufferedLogRecord' does not exist in the namespace 'Microsoft.Extensions.Logging' (are you missing an assembly reference?)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@

<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.DependencyInjection.Abstractions\ref\Microsoft.Extensions.DependencyInjection.Abstractions.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Diagnostics.DiagnosticSource\ref\System.Diagnostics.DiagnosticSource.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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.Diagnostics;

namespace Microsoft.Extensions.Logging.Abstractions
{
/// <summary>
/// State representing a buffered log record.
/// </summary>
/// <remarks>
/// Objects of this type are reused over time to reduce
/// allocations.
/// </remarks>
public abstract class BufferedLogRecord
{
/// <summary>
/// Gets the time when the log record was first created.
/// </summary>
public abstract DateTimeOffset Timestamp { get; }

/// <summary>
/// Gets the record's log level, indicating it rough importance
/// </summary>
public abstract LogLevel LogLevel { get; }

/// <summary>
/// Gets the records event id.
/// </summary>
public abstract EventId EventId { get; }

/// <summary>
/// Gets an optional exception string for this record.
/// </summary>
public virtual string? Exception { get => null; }

/// <summary>
/// Gets an activity span id for this record, representing the state of the thread that created the record.
/// </summary>
public virtual ActivitySpanId? ActivitySpanId { get => null; }

/// <summary>
/// Gets an activity trace id for this record, representing the state of the thread that created the record.
/// </summary>
public virtual ActivityTraceId? ActivityTraceId { get => null; }

/// <summary>
/// Gets the ID of the thread that created the log record.
/// </summary>
public virtual int? ManagedThreadId { get => null; }

/// <summary>
/// Gets the formatted log message.
/// </summary>
public virtual string? FormattedMessage { get => null; }

/// <summary>
/// Gets the original log message template.
/// </summary>
public virtual string? MessageTemplate { get => null; }

/// <summary>
/// Gets the variable set of name/value pairs associated with the record.
/// </summary>
public virtual IReadOnlyList<KeyValuePair<string, object?>> Attributes { get => Array.Empty<KeyValuePair<string, object?>>(); }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;

namespace Microsoft.Extensions.Logging.Abstractions
{
/// <summary>
/// Logging providers can implement this interface to indicate they support buffered logging.
/// </summary>
/// <remarks>
/// A logging provider normally exposes an <see cref="ILogger" /> interface that gets invoked by the
/// logging infrastructure whenever it’s time to log a piece of state.
///
/// The logging infrastructure will type-test the <c>ILogger</c> object to determine if
/// it supports the <c>IBufferedLogger</c> interface also. If it does, that tells the
/// logging infrastructure that the logging provider supports buffering. Whenever log
/// buffering is enabled, buffered log records will be delivered to the logging provider
/// via the <c>IBufferedLogger</c> interface.
///
/// If a logging provider does not support log buffering, then it will always be given
/// unbuffered log records. In other words, whether or not buffering is requested by
/// the user, it will not happen for those log providers.
/// </remarks>
public interface IBufferedLogger
{
/// <summary>
/// Delivers a batch of buffered log records to a logging provider.
/// </summary>
/// <param name="records">The buffered log records to log.</param>
/// <remarks>
/// Once this function returns, the implementation should no longer access the records
/// or state referenced by these records since they will get recycled.
/// </remarks>
void LogRecords(IEnumerable<BufferedLogRecord> records);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Microsoft.Extensions.Logging.Abstractions.NullLogger</PackageDescription>
<ProjectReference Include="..\gen\Microsoft.Extensions.Logging.Generators.Roslyn4.4.csproj"
ReferenceOutputAssembly="false"
PackAsAnalyzer="true" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Diagnostics.DiagnosticSource\src\System.Diagnostics.DiagnosticSource.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected ConsoleFormatter(string name)
/// Writes the log message to the specified TextWriter.
/// </summary>
/// <remarks>
/// if the formatter wants to write colors to the console, it can do so by embedding ANSI color codes into the string
/// If the formatter wants to write colors to the console, it can do so by embedding ANSI color codes into the string
/// </remarks>
/// <param name="logEntry">The log entry.</param>
/// <param name="scopeProvider">The provider of scope data.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.Versioning;
Expand All @@ -13,7 +14,7 @@ namespace Microsoft.Extensions.Logging.Console
/// A logger that writes messages in the console.
/// </summary>
[UnsupportedOSPlatform("browser")]
internal sealed class ConsoleLogger : ILogger
internal sealed class ConsoleLogger : ILogger, IBufferedLogger
{
private readonly string _name;
private readonly ConsoleLoggerProcessor _queueProcessor;
Expand Down Expand Up @@ -69,6 +70,33 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
_queueProcessor.EnqueueMessage(new LogMessageEntry(computedAnsiString, logAsError: logLevel >= Options.LogToStandardErrorThreshold));
}

/// <inheritdoc />
public void LogRecords(IEnumerable<BufferedLogRecord> records)
{
ThrowHelper.ThrowIfNull(records);

t_stringWriter ??= new StringWriter();

foreach (var rec in records)
{
var logEntry = new LogEntry<BufferedLogRecord>(rec.LogLevel, _name, rec.EventId, rec, null, (s, e) => s.FormattedMessage ?? string.Empty);
Formatter.Write(in logEntry, null, t_stringWriter);

var sb = t_stringWriter.GetStringBuilder();
if (sb.Length == 0)
{
continue;
}
string computedAnsiString = sb.ToString();
sb.Clear();
if (sb.Capacity > 1024)
{
sb.Capacity = 1024;
}
_queueProcessor.EnqueueMessage(new LogMessageEntry(computedAnsiString, logAsError: rec.LogLevel >= Options.LogToStandardErrorThreshold));
}
}

/// <inheritdoc />
public bool IsEnabled(LogLevel logLevel)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,37 @@ public JsonConsoleFormatter(IOptionsMonitor<JsonConsoleFormatterOptions> options

public override void Write<TState>(in LogEntry<TState> logEntry, IExternalScopeProvider? scopeProvider, TextWriter textWriter)
{
string message = logEntry.Formatter(logEntry.State, logEntry.Exception);
if (logEntry.Exception == null && message == null)
if (logEntry.State is BufferedLogRecord bufferedRecord)
{
return;
string message = bufferedRecord.FormattedMessage ?? string.Empty;
if (bufferedRecord.Exception == null && message == null)
{
return;
}

WriteInternal(scopeProvider, textWriter, message, bufferedRecord.LogLevel, logEntry.Category, bufferedRecord.EventId.Id, bufferedRecord.Exception,
bufferedRecord.Attributes.Count > 0, null, bufferedRecord.Attributes as IReadOnlyList<KeyValuePair<string, object?>>, bufferedRecord.Timestamp);
}
else
{
string message = logEntry.Formatter(logEntry.State, logEntry.Exception);
if (logEntry.Exception == null && message == null)
{
return;
}

// We extract most of the work into a non-generic method to save code size. If this was left in the generic
// method, we'd get generic specialization for all TState parameters, but that's unnecessary.
WriteInternal(scopeProvider, textWriter, message, logEntry.LogLevel, logEntry.Category, logEntry.EventId.Id, logEntry.Exception,
logEntry.State != null, logEntry.State?.ToString(), logEntry.State as IReadOnlyCollection<KeyValuePair<string, object>>);
DateTimeOffset stamp = FormatterOptions.UseUtcTimestamp ? DateTimeOffset.UtcNow : DateTimeOffset.Now;

// We extract most of the work into a non-generic method to save code size. If this was left in the generic
// method, we'd get generic specialization for all TState parameters, but that's unnecessary.
WriteInternal(scopeProvider, textWriter, message, logEntry.LogLevel, logEntry.Category, logEntry.EventId.Id, logEntry.Exception?.ToString(),
logEntry.State != null, logEntry.State?.ToString(), logEntry.State as IReadOnlyList<KeyValuePair<string, object?>>, stamp);
}
}

private void WriteInternal(IExternalScopeProvider? scopeProvider, TextWriter textWriter, string message, LogLevel logLevel,
string category, int eventId, Exception? exception, bool hasState, string? stateMessage, IReadOnlyCollection<KeyValuePair<string, object>>? stateProperties)
private void WriteInternal(IExternalScopeProvider? scopeProvider, TextWriter textWriter, string? message, LogLevel logLevel,
string category, int eventId, string? exception, bool hasState, string? stateMessage, IReadOnlyList<KeyValuePair<string, object?>>? stateProperties,
DateTimeOffset stamp)
{
const int DefaultBufferSize = 1024;
using (var output = new PooledByteBufferWriter(DefaultBufferSize))
Expand All @@ -52,8 +69,7 @@ private void WriteInternal(IExternalScopeProvider? scopeProvider, TextWriter tex
var timestampFormat = FormatterOptions.TimestampFormat;
if (timestampFormat != null)
{
DateTimeOffset dateTimeOffset = FormatterOptions.UseUtcTimestamp ? DateTimeOffset.UtcNow : DateTimeOffset.Now;
writer.WriteString("Timestamp", dateTimeOffset.ToString(timestampFormat));
writer.WriteString("Timestamp", stamp.ToString(timestampFormat));
}
writer.WriteNumber(nameof(LogEntry<object>.EventId), eventId);
writer.WriteString(nameof(LogEntry<object>.LogLevel), GetLogLevelString(logLevel));
Expand All @@ -62,7 +78,7 @@ private void WriteInternal(IExternalScopeProvider? scopeProvider, TextWriter tex

if (exception != null)
{
writer.WriteString(nameof(Exception), exception.ToString());
writer.WriteString(nameof(Exception), exception);
}

if (hasState)
Expand All @@ -71,7 +87,7 @@ private void WriteInternal(IExternalScopeProvider? scopeProvider, TextWriter tex
writer.WriteString("Message", stateMessage);
if (stateProperties != null)
{
foreach (KeyValuePair<string, object> item in stateProperties)
foreach (KeyValuePair<string, object?> item in stateProperties)
{
WriteItem(writer, item);
}
Expand Down Expand Up @@ -131,11 +147,11 @@ private void WriteScopeInformation(Utf8JsonWriter writer, IExternalScopeProvider
writer.WriteStartArray("Scopes");
scopeProvider.ForEachScope((scope, state) =>
{
if (scope is IEnumerable<KeyValuePair<string, object>> scopeItems)
if (scope is IEnumerable<KeyValuePair<string, object?>> scopeItems)
{
state.WriteStartObject();
state.WriteString("Message", scope.ToString());
foreach (KeyValuePair<string, object> item in scopeItems)
foreach (KeyValuePair<string, object?> item in scopeItems)
{
WriteItem(state, item);
}
Expand All @@ -150,7 +166,7 @@ private void WriteScopeInformation(Utf8JsonWriter writer, IExternalScopeProvider
}
}

private static void WriteItem(Utf8JsonWriter writer, KeyValuePair<string, object> item)
private static void WriteItem(Utf8JsonWriter writer, KeyValuePair<string, object?> item)
{
var key = item.Key;
switch (item.Value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,32 @@ public void Dispose()

public override void Write<TState>(in LogEntry<TState> logEntry, IExternalScopeProvider? scopeProvider, TextWriter textWriter)
{
string message = logEntry.Formatter(logEntry.State, logEntry.Exception);
if (logEntry.Exception == null && message == null)
if (logEntry.State is BufferedLogRecord bufferedRecord)
{
return;
string message = bufferedRecord.FormattedMessage ?? string.Empty;
if (bufferedRecord.Exception == null && message == null)
{
return;
}

WriteInternal(scopeProvider, textWriter, message, bufferedRecord.LogLevel, bufferedRecord.EventId.Id, bufferedRecord.Exception, logEntry.Category, bufferedRecord.Timestamp);
}
else
{
string message = logEntry.Formatter(logEntry.State, logEntry.Exception);
if (logEntry.Exception == null && message == null)
{
return;
}

// We extract most of the work into a non-generic method to save code size. If this was left in the generic
// method, we'd get generic specialization for all TState parameters, but that's unnecessary.
WriteInternal(scopeProvider, textWriter, message, logEntry.LogLevel, logEntry.EventId.Id, logEntry.Exception, logEntry.Category);
// We extract most of the work into a non-generic method to save code size. If this was left in the generic
// method, we'd get generic specialization for all TState parameters, but that's unnecessary.
WriteInternal(scopeProvider, textWriter, message, logEntry.LogLevel, logEntry.EventId.Id, logEntry.Exception?.ToString(), logEntry.Category, GetCurrentDateTime());
}
}

private void WriteInternal(IExternalScopeProvider? scopeProvider, TextWriter textWriter, string message, LogLevel logLevel,
int eventId, Exception? exception, string category)
int eventId, string? exception, string category, DateTimeOffset stamp)
{
ConsoleColors logLevelColors = GetLogLevelConsoleColors(logLevel);
string logLevelString = GetLogLevelString(logLevel);
Expand All @@ -67,8 +80,7 @@ private void WriteInternal(IExternalScopeProvider? scopeProvider, TextWriter tex
string? timestampFormat = FormatterOptions.TimestampFormat;
if (timestampFormat != null)
{
DateTimeOffset dateTimeOffset = GetCurrentDateTime();
timestamp = dateTimeOffset.ToString(timestampFormat);
timestamp = stamp.ToString(timestampFormat);
}
if (timestamp != null)
{
Expand Down Expand Up @@ -114,7 +126,7 @@ private void WriteInternal(IExternalScopeProvider? scopeProvider, TextWriter tex
if (exception != null)
{
// exception message
WriteMessage(textWriter, exception.ToString(), singleLine);
WriteMessage(textWriter, exception, singleLine);
}
if (singleLine)
{
Expand Down
Loading
Loading