
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Provides utilities to facilitate metrics (timers, counters, gauges, meters, healthchecks) on top of Serilog. SerilogMetrics2 extends the original SerilogMetrics to provide task timing and unscoped section timing.
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.
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.
FAQs
Provides utilities to facilitate metrics (timers, counters, gauges, meters, healthchecks) on top of Serilog. SerilogMetrics2 extends the original SerilogMetrics to provide task timing and unscoped section timing.
We found that serilogmetrics2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.