ILogger Interface

Represents a type used to perform logging.

Namespace
Microsoft.Extensions.Logging
Assemblies
  • Microsoft.Extensions.Logging.Abstractions

Syntax

public interface ILogger
interface Microsoft.Extensions.Logging.ILogger

Methods

BeginScope<TState>(TState)

Begins a logical operation scope.

Arguments:state (TState) – The identifier for the scope.
Return type:System.IDisposable
Returns:An IDisposable that ends the logical operation scope on dispose.
IDisposable BeginScope<TState>(TState state)
IsEnabled(Microsoft.Extensions.Logging.LogLevel)

Checks if the given <em>logLevel</em> is enabled.

Arguments:logLevel (Microsoft.Extensions.Logging.LogLevel) – level to be checked.
Return type:System.Boolean
Returns:<code>true</code> if enabled.
bool IsEnabled(LogLevel logLevel)
Log<TState>(Microsoft.Extensions.Logging.LogLevel, Microsoft.Extensions.Logging.EventId, TState, System.Exception, System.Func<TState, System.Exception, System.String>)

Writes a log entry.

Arguments:
  • logLevel (Microsoft.Extensions.Logging.LogLevel) – Entry will be written on this level.
  • eventId (Microsoft.Extensions.Logging.EventId) – Id of the event.
  • state (TState) – The entry to be written. Can be also an object.
  • exception (System.Exception) – The exception related to this entry.
  • formatter (System.Func<TState, System.Exception>) – Function to create a <code>string</code> message of the <em>state</em> and <em>exception</em>.
void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)