Serilog.Sinks.RavenDB
A Serilog sink that writes events as documents to RavenDB.
Package - Serilog.Sinks.RavenDB | Platforms - .NET 4.5
var logs = new DocumentStore { ConnectionStringName = "Logs" }.Initialize();
var log = new LoggerConfiguration()
.WriteTo.RavenDB(logs)
.CreateLogger();
You'll need to create a database on the server for logs, and specify this as your default database in the connection string or DocumentStore.DefaultDatabase
. In the alternative, you can pass a default database when configuring the RavenDB sink. More information.
You can also configure the sink through your application config file using Serilog.Settings.AppSettings
Log.Logger = new LoggerConfiguration()
.ReadFrom.AppSettings()
.CreateLogger();
<connectionStrings>
<add name="Logs" connectionString="Url=http://[RAVEN_DB_SERVER]:8080/;DefaultDatabase=[OPTIONAL_DEFAULT_DATABASE]" />
</connectionStrings>
<appSettings>
<add key="serilog:minimum-level" value="Information" />
<add key="serilog:using:RavenDB" value="Serilog.Sinks.RavenDB" />
<add key="serilog:write-to:RavenDB.connectionStringName" value="Logs" />
<add key="serilog:write-to:RavenDB.defaultDatabase" value="[DEFAULT_DATABASE]" />
</appSettings>
Automatic Log Record Expiration
If you install the RavenDB expiration bundle on the database where log records are stored, you can configure the
sink to automatically delete log records by passing errorExpiration
(for fatal and error messages) and
expiration
(for all other messages). If you pass one, you should pass both. Timeout.InfiniteTimeSpan
indicates that
messages of the appropriate type will never be deleted by the expiration bundle.