Metrics.NET
Metrics.NET copied to clipboard
Monitoring windows service using Metrics.Net
Hi, How do we configure/implement Metrics.Net library for monitoring windows services? We have need to monitor http services and windows services (running in the background) as well. Please let me know if anyone had done this before or have some ideas.
thanks, Raghu
I have some experience hosting Metrics.Net inside a Windows Service (using Topshelf). In Program.cs I have the following Topshelf specific code:
var topshelfExitCode = HostFactory.Run(serviceConfiguration =>
{
Log.Logger.Bootstrap(new ConfigurationFromAppConfig());
serviceConfiguration.UseSerilog(Log.Logger);
serviceConfiguration.Service<ApiService>(serviceInstance =>
{
serviceInstance.ConstructUsing(() => new ApiService());
and in ApiService.cs I have
public void Start()
{
try
{
Uri baseAddress = LoadUrl();
_webApiServer = WebApp.Start<Startup>(url: baseAddress.ToString());
Metric.Config.WithHttpEndpoint("http://localhost:1337/").WithAllCounters().WithReporting(r => r.WithTextFileReport(@"c:\temp\APIServiceReports.log", TimeSpan.FromSeconds(5)));
}
catch (Exception ex)
{
...
}
}