SerilogMetrics2

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") );
t.Wait();
Logger.EndTimedOperation("any message", "myID");
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"));
logger.LogTaskExecutionTime(t, "ExampleMethodAsync", "myid1");
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.