RavenDB.StructuredLogger
4.0.2
See the version list below for details.
dotnet add package RavenDB.StructuredLogger --version 4.0.2
NuGet\Install-Package RavenDB.StructuredLogger -Version 4.0.2
<PackageReference Include="RavenDB.StructuredLogger" Version="4.0.2" />
paket add RavenDB.StructuredLogger --version 4.0.2
#r "nuget: RavenDB.StructuredLogger, 4.0.2"
// Install RavenDB.StructuredLogger as a Cake Addin #addin nuget:?package=RavenDB.StructuredLogger&version=4.0.2 // Install RavenDB.StructuredLogger as a Cake Tool #tool nuget:?package=RavenDB.StructuredLogger&version=4.0.2
RavenDB.StructuredLog
An ASP.NET Core logger that utilizes RavenDB to store structured logs.
<a href="https://andrewlock.net/creating-an-extension-method-for-attaching-key-value-pairs-to-scope-state-using-asp-net-core/">Structured log</a> that uses RavenDB as the log store.
Old, ugly way of logging makes for thousands of opaque logs:
- "User foo@bar.com signed in at 5:13 Oct 7"
- "User no@regerts.com signed in at 2:25 Nov 8"
- "User bar@zanz.com signed in at 3:18 Nov 21"
- "User me@me2.com signed in at 12:0 Dec 15"
- [and on and on for 1000+ entries - oiy!]
But with structured and grouped logging, you get a fewer logs that group similar logs together and makes them searchable:
{
"MessageTemplate": "User {email} signed in at {date}",
"Level": "Information",
"OccurrenceCount": 1032,
"FirstOccurrence": "2017-09-27T17:29:46.6597966+00:00",
"LastOccurrence": "2017-09-27T17:39:50.5554997+00:00",
"Occurrences": [
{
"Message": "User foo@bar.com signed in at 5:13 Oct 7",
"Level": "Information",
"Created": "2017-09-27T17:39:48.4248681+00:00",
"Category": "Sample.Controllers.HomeController",
"EventId": null,
"TemplateValues": {
"{OriginalFormat}": "User {email} signed in at {date}",
"email": "foo@bar.com",
"date": "5:13 Oct 7"
}
},
{
"Message": "User no@regerts.com signed in at 2:25 Nov 8",
"Level": "Information",
"Created": "2017-09-27T17:39:48.4248681+00:00",
"Category": "Sample.Controllers.HomeController",
"EventId": null,
"TemplateValues": {
"{OriginalFormat}": "User {email} signed in at {date}",
"email": "no@regerts.com",
"date": "2:25 Nov 8"
}
}
]
}
The end result is humans can easily understand what errors are occurring in your software and how often. Moreover, unlike old school logging where logs are giant opaque strings, structured logs are searchable as their template values are extracted and stored outside the log message.
Instructions
- In Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
// Add RavenDB structured logging.
services.AddLogging(builder => builder.AddRavenStructuredLogger(docStore)); // Where docStore is your RavenDB DocumentStore singleton.
...
}
- Use logging as you normally would inside your controllers and services:
public class HomeController : Controller
{
private ILogger<HomeController> logger;
public HomeController(ILogger<HomeController> logger)
{
this.logger = logger;
}
public string Get()
{
// Simple logging
logger.LogInformation("Hi there!");
// Logging with templates
logger.LogInformation("The time on the server is {time}.", DateTime.UtcNow);
// Logging exceptions
logger.LogError(exception, "Woops, an error occurred");
// Logging exceptions with templates
logger.LogError(exception, "Woops, an error occurred executing {action} at {date}", this.ControllerContext.ActionDescriptor.ActionName, DateTime.UtcNow);
// Logging with scopes
using (logger.BeginScope(42))
{
logger.LogInformation("This message will have forty-two stored with it");
}
// Logging with multiple scopes and scope templates.
using (logger.BeginScope(42))
using (logger.BeginScope("The current user is {user}", User.Identity.Name))
using (logger.BeginKeyValueScope(nameof(totalCount), totalCount))
{
logger.LogInformation("This log will contain forty-two, the current signed in user name, and a key-value pair containing the name of the totalCount variable and its value.");
}
...
}
}
- You're done!
Need help? See the sample app.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Configuration.Abstractions (>= 2.0.0)
- Microsoft.Extensions.DependencyInjection (>= 2.0.0)
- Microsoft.Extensions.Logging (>= 2.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 2.0.0)
- RavenDB.Client (>= 4.0.0)
- System.Reactive (>= 3.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
7.1.0 | 132 | 3/26/2024 |
7.0.0 | 157 | 1/13/2024 |
6.0.1 | 879 | 9/2/2020 |
6.0.0 | 478 | 7/26/2020 |
5.1.0 | 509 | 5/15/2020 |
5.0.0 | 788 | 11/28/2019 |
4.2.1 | 646 | 9/11/2019 |
4.2.0 | 529 | 9/9/2019 |
4.1.0 | 542 | 9/4/2019 |
4.0.8 | 675 | 5/16/2019 |
4.0.7 | 1,047 | 8/15/2018 |
4.0.6 | 926 | 8/13/2018 |
4.0.5 | 977 | 7/10/2018 |
4.0.4 | 1,106 | 7/3/2018 |
4.0.3 | 1,201 | 3/13/2018 |
4.0.2 | 1,079 | 3/13/2018 |
4.0.1 | 1,143 | 2/12/2018 |
4.0.0 | 1,115 | 2/11/2018 |
2.0.2 | 1,126 | 1/11/2018 |
2.0.1 | 1,272 | 11/27/2017 |
2.0.0 | 1,178 | 10/17/2017 |
1.0.1 | 1,091 | 10/3/2017 |
1.0.0 | 1,112 | 9/27/2017 |
Exceptions are grouped by message + function + line