SerilogMetrics2 2.1.7

dotnet add package SerilogMetrics2 --version 2.1.7
NuGet\Install-Package SerilogMetrics2 -Version 2.1.7
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SerilogMetrics2" Version="2.1.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SerilogMetrics2 --version 2.1.7
#r "nuget: SerilogMetrics2, 2.1.7"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SerilogMetrics2 as a Cake Addin
#addin nuget:?package=SerilogMetrics2&version=2.1.7

// Install SerilogMetrics2 as a Cake Tool
#tool nuget:?package=SerilogMetrics2&version=2.1.7

SerilogMetrics2 Build status NuGet

Serilog combines the best features of traditional and structured diagnostic logging in an easy-to-use package and Serilog.Metrics extends this logging framework with measure capabilities like counters, timers, meters and gauges.

Get started

To quickly get started, add the SerilogMetrics2 package to your solution using the NuGet Package manager or run the following command in the Package Console Window:

Install-Package SerilogMetrics2

The metrics method extensions are extending the ILogger interface of Serilog. So just reference the Serilog namespace and you can invoke the functionality from the logger. SerilogMetrics2 extends functionality of SerilogMetrics which doesn't seem to be supported any longer. The following extension methods are added:

public static IDisposable BeginUnscopedTimedOperation(string description, string id)

This method is exactly like BeginTimedOperation except it does not require that the scope of the timing be marked with braces. The EndTimedOperation() method may be called from anywhere in the code as long as the logger is in scope.

This method takes the same arguments as BeginTimedOperation but it requires a unique ID as a string, which will be used when EndTimedOperation is called. See example below.

e.g.

logger.BeginUnscopedTimedOperation("Time a thread sleep for 2 seconds.", "myID");
var t = Task.Run(() => MyLongRunningTask("Task") );
// Lots of other code executing while task is running
// ...
// ...
t.Wait();
// EndTimedOperation must be called with the same string ID used above.
Logger.EndTimedOperation("any message", "myID"); // Note: SAME ID as above

// Note: ID must match the call to BeginUnscopedTimedOperation
public static EndTimedOperation(string description, string id); 

public static IDisposable LogTaskExecutionTime(Task t, string description, string uniqueID)

This method takes the same arguments as BeginTimedOperation but also requires a Task task and string ID which is unique to this call. This is a "set and forget" method which creates an awaiter for the task and when the task finishes, it will log the time spent performing the task.

e.g.

static void LongRunningTask(String s)
{
    Thread.Sleep(2500);
}

Task t = Task.Run(() => LongRunningTask("SerilogMetrics2"));    // no await
logger.LogTaskExecutionTime(t, "ExampleMethodAsync", "myid1");  // will log when above task completes

For example;

var logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .WriteTo.Trace()
                .CreateLogger();

using (logger.BeginTimedOperation("Time a thread sleep for 2 seconds."))
{
     Thread.Sleep(2000);
}

See the documentation for more details.

Copyright © 2016 Serilog Metrics Contributors - Provided under the Apache License, Version 2.0.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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 netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.1 is compatible. 
.NET Framework net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.1.7 9,102 12/3/2021
2.1.6 241 12/3/2021
2.1.5 258 12/3/2021
2.1.4 249 12/3/2021
2.1.3 242 12/2/2021
2.1.2 953 12/1/2021
2.1.1 960 12/1/2021
2.1.0 893 12/1/2021