Custom logging
Experienced users (familiar with .NET development) can configure logging to fit their needs using Serilog configuration file.
This file must be named logging.json
and located in the configuration directory.
logging: { useCustomConfig: true }
must be set in theconfig.yaml
configuration file.
Any library dependencies not included in the release must be copied from e.g. nuget.org to the installation directory (where other Serilog.*.dll
files are located), including their transitive dependencies.
Extra care should be taken to ensure that the supplied dll files are compatible with the version of Serilog
and other pre-existing libraries.
Replacing the already existing Serilog.*.dll
files with different versions is sometimes possible but not recommended since it may lead to application instability and failures.
Configuration example
The example shows how to configure Serilog to write to a file, to the console and send errors to an email address.
Since Serilog.Sinks.Email
is not included in the release, it needs to be supplied manually, including all its dependencies:
Serilog.Sinks.Email
Serilog.Sinks.PeriodicBatching
(dependency ofSerilog.Sinks.Email
)Mailkit
(dependency ofSerilog.Sinks.Email
)
logging.json
{
"Serilog": {
"Using": [
"Serilog.Sinks.Console",
"Serilog.Sinks.File",
"Serilog.Sinks.Email"
],
"MinimumLevel": "Information",
"WriteTo": [
{
"Name": "Console"
},
{
"Name": "File",
"Args": {
"path": "D:\\logs\\buru.log",
"restrictedToMinimumLevel": "Warning"
}
},
{
"Name": "Email",
"Args": {
"restrictedToMinimumLevel": "Error",
"fromEmail": "mail@rebex.net",
"toEmail": "mail@rebex.net",
"mailServer": "smtp"
}
}
]
}
}
config.yaml
logging:
useCustomConfig: true
Nuget versions
Library | Buru 2.5.1+ | Buru 2.6.0+ | Buru 2.7.2+ |
---|---|---|---|
.NET | netcoreapp3.1 | net6.0 | net6.0 |
Serilog | 2.10 | 2.10 | 2.11 |
Serilog.Extensions.Hosting | 4.1.2 | 4.2 | 5.0.1 |
Serilog.Extensions.Logging | 3.1 | 3.1 | 3.1 |
Serilog.Formatting.Compact | 1.1 | 1.1 | 1.1 |
Serilog.Settings.Configuration | 3.3 | 3.3 | 3.3 |
Serilog.Sinks.ColoredConsole | 3.0.1 | 3.0.1 | 3.0.1 |
Serilog.Sinks.Console | 4.0 | 4.0.1 | 4.0.1 |
Serilog.Sinks.Debug | 2.0 | 2.0 | 2.0 |
Serilog.Sinks.EventLog | 3.1 | 3.1 | 3.1 |
Serilog.Sinks.File | 5.0 | 5.0 | 5.0 |
Serilog.Sinks.RollingFile | 3.3 | 3.3 | 3.3 |
Serilog.Sinks.TextWriter | 2.1 | 2.1 | 2.1 |
Notes
Access logs are distinguished by Access
Serilog property.