Table of Contents

Class MicrosoftExtensionsLogger

Namespace
RocksDbNet
Assembly
RocksDb.Net.dll

Sends RocksDb's info log to a ILogger, so it lands in the same pipeline as the rest of the application's logging.

public sealed class MicrosoftExtensionsLogger : Logger, IDisposable
Inheritance
MicrosoftExtensionsLogger
Implements
Inherited Members

Remarks

Usually attached through UseLogging(DbOptions, ILoggerFactory, string). RocksDb's levels map as follows:

RocksDbLogLevel
DebugDebug
InfoInformation
WarnWarning
ErrorError
FatalCritical
HeaderDebug

Expect volume at Information. Every time a database opens, RocksDb writes several hundred lines: its version, a summary of the files it found and every option it was opened with. It writes them without a level, so they arrive as Info and cannot be told apart from its other informational messages. In production, set the category's minimum level to Warning, as with any chatty component; the warnings and errors are what is worth keeping.

RocksDb fixes a logger's level when it is created, so the level here is the lowest the ILogger had enabled at that moment, and RocksDb does not format messages below it. Lowering the configured level later does not reach a database already open with it; pass a minimum level to the constructor to choose it explicitly instead.

That native level only filters what RocksDb logs with a level, so the unlevelled lines above get through it whatever was asked for (see issue #129). The ILogger's own filtering then decides; with an explicit minimum level, they are also dropped here when it is higher.

Messages are logged with the template {RocksDbMessage}, because RocksDb's own text contains braces that would otherwise be read as placeholders. Logging runs on RocksDb's background threads, as ILogger implementations expect; an exception from the logger is reported through UnhandledException and the line dropped.

Constructors

MicrosoftExtensionsLogger(ILogger, InfoLogLevel?)

Creates a logger that forwards RocksDb's info log to logger.

public MicrosoftExtensionsLogger(ILogger logger, InfoLogLevel? minimumLevel = null)

Parameters

logger ILogger

Where to send the log.

minimumLevel InfoLogLevel?

The lowest RocksDb level to pass on, or null for the lowest level logger has enabled now.

Methods

Log(InfoLogLevel, string)

Called by RocksDb to log a message at the specified level.

public override void Log(InfoLogLevel logLevel, string message)

Parameters

logLevel InfoLogLevel

The severity level of the message.

message string

The log message text.

ToLogLevel(InfoLogLevel)

The LogLevel a RocksDb level is logged at.

public static LogLevel ToLogLevel(InfoLogLevel level)

Parameters

level InfoLogLevel

Returns

LogLevel