- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.2k
Introduce IBufferedLogger #103138
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
          
     Merged
      
      
    
  
     Merged
                    Introduce IBufferedLogger #103138
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      5a8095c
              
                Introduce IBufferedLogger
              
              
                 43061c1
              
                Update following review
              
              
                 5f60107
              
                Apply suggestions from code review
              
              
                geeknoid f8221d0
              
                Next batch of review changes
              
              
                 71df064
              
                Another fix
              
              
                 afb13cd
              
                More fixes
              
              
                 b61c39e
              
                Merge branch 'main' into geeknoid/bufferedlog
              
              
                geeknoid File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.