Open sandboxFocus

Class SerilogLoggingBackend

Logging backend for Serilog.

Inheritance
SerilogLoggingBackend
Implements
Namespace: PostSharp.Patterns.Diagnostics.Backends.Serilog
Assembly: PostSharp.Patterns.Diagnostics.Backends.Serilog.dll
Syntax
public class SerilogLoggingBackend : TextLoggingBackend, IDisposable
Remarks

To use this backend, pass the Serilog Serilog.ILogger that writes to your sinks to the constructor, and assign the instance to DefaultBackend when the application starts.

The indentation string of each record is passed as the Indent property. Include {Indent:l} in the output template of your sinks to produce indented logs. By default, parameter values are formatted by PostSharp Logging; see SerilogLoggingBackendOptions to pass them to Serilog formatters or to add more semantic properties.

To route the events that your code logs directly with Serilog through PostSharp Logging, create a second logger that writes to the PostSharp(LoggerSinkConfiguration, string, SerilogParameterHandling) sink and use it for manual logging, while this backend keeps the logger that writes to the output sinks.

Constructors

Name Description
SerilogLoggingBackend()

Initializes a new instance of the SerilogLoggingBackend class that uses the globally shared Serilog.ILogger.

SerilogLoggingBackend(ILogger)

Initializes a new instance of the SerilogLoggingBackend class and specifies the target Serilog.ILogger.

Properties

Name Description
Logger

Gets the Serilog.ILogger passed to the constructor of the current SerilogLoggingBackend, or the globally shared Serilog.ILogger if no logger was passed to the constructor.

MessageTemplateCacheSize

Gets the number of items in the message template cache.

Options

Gets the backend options.

Methods

Name Description
ClearMessageTemplateCache()

Clears the message template cache.

CreateAsyncCustomActivityContext()

Creates a new AsyncCustomActivityLoggingContext.

CreateAsyncMethodContext()

Creates a new AsyncMethodLoggingContext for a given async method.

CreateEphemeralContext(ThreadLoggingContext)

Creates a new EphemeralLoggingContext.

CreateIteratorContext()

Creates a new IteratorLoggingContext for a given iterator method.

CreateRecordBuilder()

Creates a new LogRecordBuilder.

CreateSyncCustomActivityContext(ThreadLoggingContext)

Creates a new SyncCustomActivityLoggingContext.

CreateSyncMethodContext(ThreadLoggingContext)

Creates a new SyncMethodLoggingContext for a given normal (non-async, non-iterator) method.

CreateTypeSource(LoggingNamespaceSource, Type)

Creates a LoggingTypeSource for the given role and type.

CreateTypeSourceBySourceName(LoggingNamespaceSource, string)

Creates a LoggingTypeSource for the given role and logger name.

GetTextBackendOptions()

Gets the options.

See Also