Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Better logging (#26)
Browse files Browse the repository at this point in the history
* expanded logging

* added extra join after interrupt

* version bump

* hidden pwd

* version bump
  • Loading branch information
MindFlavor authored Nov 28, 2020
1 parent 5083275 commit 214d49f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion MindFlavor.SQLServerExporter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<Version>1.1.0.0</Version>
<Version>1.1.3.0</Version>
<Authors>Francesco Cogno</Authors>
<Copyright>Apache License Version 2.0</Copyright>
<PackageLicenseUrl>https://raw.githubusercontent.com/MindFlavor/prometheus_sql_server_exporter/master/LICENSE</PackageLicenseUrl>
Expand Down
14 changes: 12 additions & 2 deletions SQLServerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void Handler(IApplicationBuilder app)
var pts = new ParameterizedThreadStart(ProcessInstance);
Thread thread = new Thread(pts);
thread.Priority = ThreadPriority.BelowNormal;
thread.Name = instance.ConnectionString;
thread.Name = new System.Data.SqlClient.SqlConnectionStringBuilder(instance.ConnectionString).DataSource;
thread.Start(new Tuple<HttpContext, string,
System.Collections.Concurrent.ConcurrentDictionary<string, ConcurrentBag<string>>>
(context, instance.ConnectionString, dictBag));
Expand All @@ -70,6 +70,8 @@ public static void Handler(IApplicationBuilder app)
}
});
lThreads.ForEach(t => t.Join());
context.Response.StatusCode = StatusCodes.Status200OK;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
Expand Down Expand Up @@ -128,7 +130,15 @@ private static void ProcessInstance(object? o)
}
catch (Exception e)
{
logger.LogWarning($"unhandled exception: {e.ToString()}");
try
{
System.Data.SqlClient.SqlConnectionStringBuilder connBuilder = new System.Data.SqlClient.SqlConnectionStringBuilder(connectionString);
logger.LogWarning($"unhandled exception processing \"{connBuilder.DataSource}\": {e.ToString()}");
}
catch (Exception einner)
{
logger.LogWarning($"unhandled exception: {einner.ToString()}");
}
}
}
}
Expand Down

0 comments on commit 214d49f

Please sign in to comment.