Spiffy.Monitoring
6.3.1
dotnet add package Spiffy.Monitoring --version 6.3.1
NuGet\Install-Package Spiffy.Monitoring -Version 6.3.1
<PackageReference Include="Spiffy.Monitoring" Version="6.3.1" />
paket add Spiffy.Monitoring --version 6.3.1
#r "nuget: Spiffy.Monitoring, 6.3.1"
// Install Spiffy.Monitoring as a Cake Addin #addin nuget:?package=Spiffy.Monitoring&version=6.3.1 // Install Spiffy.Monitoring as a Cake Tool #tool nuget:?package=Spiffy.Monitoring&version=6.3.1
Overview
A structured logging framework for .NET that supports log analysis (e.g. Splunk) and metrics gathering (e.g. Prometheus).
Battle-tested in high-volume production environments for more than 10 years, handling over 1,000,0000,000,000 (1 trillion) requests.
Status
Package | Latest Release |
---|---|
Spiffy.Monitoring |
|
Spiffy.Monitoring.Aws |
|
Spiffy.Monitoring.NLog |
|
Spiffy.Monitoring.Prometheus |
|
Spiffy.Monitoring.Splunk |
Setup
PM> Install-Package Spiffy.Monitoring
Built-In Logging Providers
Spiffy.Monitoring
includes "built-in" logging mechanisms (Trace
and Console
).
There is no default logging behavior, you must initialize provider(s) by calling Spiffy.Monitoring.Configuration.Initialize
.
Until initialized, any published EventContext
will not be observable, so it is recommended that initialization be as early as possible when your application is starting (i.e. in the entry point).
Example
Configuration.Initialize(spiffy => { spiffy.Providers.Console(); });
Extended Providers
For extended functionality, you'll need to install a "provider package".
NOTE: the provider package need only be installed for your application's entry point assembly, it need not be installed in library packages.
NLog Provider
PM> Install-Package Spiffy.Monitoring.NLog
Example
static void Main() {
// this should be the first line of your application
Spiffy.Monitoring.Configuration.Initialize(spiffy => {
spiffy.Providers
.NLog(nlog => nlog.Targets(t => t.File()));
});
}
Multiple Providers
Multiple providers can be provied, for example, this application uses both Console
(built-in), as well as File
(NLog)
Example
Spiffy.Monitoring.Configuration.Initialize(spiffy => {
spiffy.Providers
.Console()
.NLog(nlog => nlog.Targets(t => t.File()));
});
Log
Example Program
// key-value-pairs set here appear in every event message
GlobalEventContext.Instance
.Set("Application", "MyApplication");
using (var context = new EventContext()) {
context["Key"] = "Value";
using (context.Time("LongRunning")) {
DoSomethingLongRunning();
}
try {
DoSomethingDangerous();
}
catch (Exception ex) {
context.IncludeException(ex);
}
}
Normal Entry
[2014-06-13 00:05:17.634Z] Application=MyApplication Level=Info Component=Program Operation=Main TimeElapsed=1004.2 Key=Value TimeElapsed_LongRunning=1000.2
Exception Entry
[2014-06-13 00:12:52.038Z] Application=MyApplication Level=Error Component=Program Operation=Main TimeElapsed=1027.0 Key=Value ErrorReason="An exception has ocurred" Exception_Type=ApplicationException Exception_Message="you were unlucky!" Exception_StackTrace=" at TestConsoleApp.Program.DoSomethingDangerous() in c:\src\git\github\chris-peterson\Spiffy\src\Tests\TestConsoleApp\Program.cs:line 47 at TestConsoleApp.Program.Main() in c:\src\git\github\chris-peterson\Spiffy\src\Tests\TestConsoleApp\Program.cs:line 29" InnermostException_Type=NullReferenceException InnermostException_Message="Object reference not set to an instance of an object." Exception="See Exception_* and InnermostException_* for more details" TimeElapsed_LongRunning=1000.0
Hosting Frameworks
Spiffy.Monitoring
is designed to be easy to use in any context.
The most basic usage is to instrument a specific method.
This can be achieved by "newing up" an EventContext
.
This usage mode results in Component
being set to the containing code's
class name, and Operation
is set to the containing code's method name
There are times when you may want to instrument something that's not
a specific method. One such example is an API -- in this context,
you might want to have 1 log event per request. Consider setting
Component
to be the controller name, and Operation
the action name. To acheive this, add middleware that calls
EventContext.Initialize
with the desired labels.
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
- Ben.Demystifier (>= 0.4.1)
- System.Diagnostics.StackTrace (>= 4.3.0)
- System.Diagnostics.TraceSource (>= 4.3.0)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on Spiffy.Monitoring:
Package | Downloads |
---|---|
ConsulRx
A library for consuming consul values in a continuous stream using the Reactive Extensions |
|
Spiffy.Monitoring.NLog
The NLog adapter for Spiffy.Monitoring |
|
Spiffy.Monitoring.Prometheus
The Prometheus provider for Spiffy.Monitoring |
|
Spiffy.Monitoring.Aws
AWS provider for Spiffy.Monitoring |
|
Assurance
A library to boost confidence when making code changes |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
6.3.1 | 1,165 | 1/3/2024 |
6.3.0 | 331 | 10/20/2023 |
6.2.6 | 2,865 | 6/12/2023 |
6.2.5 | 552 | 5/10/2023 |
6.2.4 | 432 | 4/27/2023 |
6.2.3 | 1,236 | 1/18/2023 |
6.2.2 | 1,432 | 1/6/2023 |
6.2.1 | 351 | 1/6/2023 |
6.2.0 | 675 | 5/2/2022 |
6.1.0 | 4,031 | 11/2/2021 |
6.0.8 | 2,165 | 8/9/2021 |
6.0.7 | 763 | 6/15/2021 |
6.0.6 | 827 | 11/12/2020 |
6.0.5 | 576 | 11/10/2020 |
6.0.3 | 685 | 10/30/2020 |
5.2.0 | 1,052 | 10/18/2019 |
5.1.2 | 6,052 | 11/12/2018 |
5.1.1 | 2,496 | 10/19/2018 |
5.1.0 | 11,208 | 1/15/2018 |
5.0.0 | 1,532 | 10/25/2017 |
4.0.5 | 12,553 | 7/5/2017 |
4.0.4 | 1,258 | 6/25/2017 |
4.0.3 | 1,331 | 6/20/2017 |
4.0.2 | 1,898 | 5/23/2017 |
4.0.1 | 2,068 | 4/16/2017 |
3.1.0 | 2,217 | 1/26/2017 |
3.0.0 | 4,321 | 7/27/2016 |
2.0.1 | 1,530 | 6/17/2015 |
2.0.0 | 2,083 | 4/30/2015 |
1.2.0 | 1,701 | 4/6/2015 |
1.1.0 | 1,703 | 3/17/2015 |
1.0.0 | 1,861 | 6/12/2014 |
# Changes
* [Bugfix: Setting Component and Operation via indexer](https://github.com/chris-peterson/spiffy/commit/9fade3c877675249e6bd37312c0610edb7b1784f)
**Full Changelog**: https://github.com/chris-peterson/spiffy/compare/6.3.0...6.3.1