-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Introduce IBufferedLogger * Update following review * Apply suggestions from code review Co-authored-by: Stephen Toub <stoub@microsoft.com> * Next batch of review changes * Another fix * More fixes --------- Co-authored-by: Martin Taillefer <mataille@microsoft.com> Co-authored-by: Stephen Toub <stoub@microsoft.com>
- Loading branch information
1 parent
c19c03e
commit 223249f
Showing
12 changed files
with
294 additions
and
41 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
70 changes: 70 additions & 0 deletions
70
src/libraries/Microsoft.Extensions.Logging.Abstractions/src/BufferedLogRecord.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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// 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> | ||
/// Represents a buffered log record to be written in batch to an <see cref="IBufferedLogger" />. | ||
/// </summary> | ||
/// <remarks> | ||
/// Instances of this type may be pooled and reused. Implementations of <see cref="IBufferedLogger" /> must | ||
/// not hold onto instance of <see cref="BufferedLogRecord" /> passed to its <see cref="IBufferedLogger.LogRecords" /> method | ||
/// beyond the invocation of that method. | ||
/// </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 logging severity level. | ||
/// </summary> | ||
public abstract LogLevel LogLevel { get; } | ||
|
||
/// <summary> | ||
/// Gets the record's event id. | ||
/// </summary> | ||
public abstract EventId EventId { get; } | ||
|
||
/// <summary> | ||
/// Gets an exception string for this record. | ||
/// </summary> | ||
public virtual string? Exception => 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 => 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 => null; | ||
|
||
/// <summary> | ||
/// Gets the ID of the thread that created the log record. | ||
/// </summary> | ||
public virtual int? ManagedThreadId => null; | ||
|
||
/// <summary> | ||
/// Gets the formatted log message. | ||
/// </summary> | ||
public virtual string? FormattedMessage => null; | ||
|
||
/// <summary> | ||
/// Gets the original log message template. | ||
/// </summary> | ||
public virtual string? MessageTemplate => null; | ||
|
||
/// <summary> | ||
/// Gets the variable set of name/value pairs associated with the record. | ||
/// </summary> | ||
public virtual IReadOnlyList<KeyValuePair<string, object?>> Attributes => []; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/libraries/Microsoft.Extensions.Logging.Abstractions/src/IBufferedLogger.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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// 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> | ||
/// Represents the ability of a logging provider to support buffered logging. | ||
/// </summary> | ||
/// <remarks> | ||
/// A logging provider implements the <see cref="ILogger" /> interface that gets invoked by the | ||
/// logging infrastructure whenever it’s time to log a piece of state. | ||
/// | ||
/// A logging provider may also optionally implement the <see cref="IBufferedLogger" /> interface. | ||
/// The logging infrastructure may type-test the <see cref="ILogger" /> object to determine if | ||
/// it supports the <see cref="IBufferedLogger" /> interface. If it does, that indicates to the | ||
/// logging infrastructure that the logging provider supports buffering. Whenever log | ||
/// buffering is enabled, buffered log records may be delivered to the logging provider | ||
/// in a batch via <see cref="IBufferedLogger.LogRecords" />. | ||
/// | ||
/// If a logging provider does not support log buffering, then it will always be given | ||
/// unbuffered log records. If a logging provider does support log buffering, whether its | ||
/// <see cref="ILogger" /> or <see cref="IBufferedLogger" /> implementation is used is | ||
/// determined by the log producer. | ||
/// </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 the instances may be reused to represent other logs. | ||
/// </remarks> | ||
void LogRecords(IEnumerable<BufferedLogRecord> records); | ||
} | ||
} |
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
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.