Skip to content

Commit 8ca52e6

Browse files
committed
Trace stack dump and log at warning for exceptions
1 parent ac30c26 commit 8ca52e6

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

IISWithBindings/Jobs/Inventory.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Management.Automation.Runspaces;
55
using System.Net;
66
using System.Security;
7+
using Keyfactor.Logging;
78
using Keyfactor.Orchestrators.Common.Enums;
89
using Keyfactor.Orchestrators.Extensions;
910
using Microsoft.Extensions.Logging;
@@ -122,15 +123,17 @@ private JobResult PerformInventory(InventoryJobConfiguration config, SubmitInven
122123
}
123124
catch (Exception ex)
124125
{
125-
_logger.LogTrace(ex.Message);
126+
_logger.LogTrace(LogHandler.FlattenException(ex));
127+
128+
string failureMessage = $"Inventory job failed for Site '{config.CertificateStoreDetails.StorePath}' on server '{config.CertificateStoreDetails.ClientMachine}' with error: '{ex.Message}'";
129+
_logger.LogWarning(failureMessage);
130+
126131
return new JobResult
127132
{
128133
Result = OrchestratorJobStatusJobResult.Failure,
129134
JobHistoryId = config.JobHistoryId,
130-
FailureMessage =
131-
$"Site {config.CertificateStoreDetails.StorePath} on server {config.CertificateStoreDetails.ClientMachine}: {ex.Message}"
135+
FailureMessage = failureMessage
132136
};
133-
134137
}
135138
}
136139

IISWithBindings/Jobs/Management.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Management.Automation.Runspaces;
55
using System.Net;
66
using System.Security.Cryptography.X509Certificates;
7+
using Keyfactor.Logging;
78
using Keyfactor.Orchestrators.Common.Enums;
89
using Keyfactor.Orchestrators.Extensions;
910
using Microsoft.Extensions.Logging;
@@ -140,13 +141,16 @@ private JobResult PerformRemoval(ManagementJobConfiguration config)
140141
}
141142
catch (Exception ex)
142143
{
143-
_logger.LogTrace(ex.Message);
144+
_logger.LogTrace(LogHandler.FlattenException(ex));
145+
146+
string failureMessage = $"Remove job failed for Site '{config.CertificateStoreDetails.StorePath}' on server '{config.CertificateStoreDetails.ClientMachine}' with error: '{ex.Message}'";
147+
_logger.LogWarning(failureMessage);
148+
144149
return new JobResult
145150
{
146-
Result = OrchestratorJobStatusJobResult.Failure,
151+
Result = OrchestratorJobStatusJobResult.Failure,
147152
JobHistoryId = config.JobHistoryId,
148-
FailureMessage =
149-
$"Site {config.CertificateStoreDetails.StorePath} on server {config.CertificateStoreDetails.ClientMachine}: {ex.Message}"
153+
FailureMessage = failureMessage
150154
};
151155
}
152156
}
@@ -318,13 +322,16 @@ function InstallPfxToMachineStore([byte[]]$bytes, [string]$password, [string]$st
318322
}
319323
catch (Exception ex)
320324
{
321-
_logger.LogTrace(ex.Message);
325+
_logger.LogTrace(LogHandler.FlattenException(ex));
326+
327+
string failureMessage = $"Add job failed for Site '{config.CertificateStoreDetails.StorePath}' on server '{config.CertificateStoreDetails.ClientMachine}' with error: '{ex.Message}'";
328+
_logger.LogWarning(failureMessage);
329+
322330
return new JobResult
323331
{
324332
Result = OrchestratorJobStatusJobResult.Failure,
325333
JobHistoryId = config.JobHistoryId,
326-
FailureMessage =
327-
$"Site {config.CertificateStoreDetails.StorePath} on server {config.CertificateStoreDetails.ClientMachine}: {ex.Message}"
334+
FailureMessage = failureMessage
328335
};
329336
}
330337
}

0 commit comments

Comments
 (0)