Skip to content

Commit 13f159f

Browse files
committed
Fix namespace and old reference to VTEXSplunkEntry
#9
1 parent 492ff2a commit 13f159f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using Microsoft.Extensions.Logging;
3+
using VTEX.SampleWebAPI.Logging;
4+
5+
namespace VTEX.SampleWebAPI
6+
{
7+
public static class VTEXSplunkEntryExtensions
8+
{
9+
static readonly EventId EmptyEventId = new EventId();
10+
11+
public static void DefineVTEXLog(this ILogger logger, LogLevel logLevel, string workflowType, string workflowInstance, string account = "", Exception exception = null, params Tuple<string, string>[] extraParameters)
12+
{
13+
string formattedMessage = string.Empty;
14+
logger.Log(logLevel,
15+
EmptyEventId,
16+
new VTEXSplunkEntry(workflowType, workflowInstance, account, exception, extraParameters),
17+
exception, (VTEXSplunkEntry arg1, Exception arg2) =>
18+
{
19+
if (string.IsNullOrWhiteSpace(formattedMessage))
20+
{
21+
var eventSegment = $"Event '{workflowType}' on {workflowInstance}";
22+
var exceptionSegment = "";
23+
if (exception != null)
24+
exceptionSegment = $"Exception type: {exception.GetType().FullName}. Exception message: {exception.Message}";
25+
var accountSegment = !string.IsNullOrWhiteSpace(account) ? account : "-";
26+
formattedMessage = string.Format($"[{logLevel}] {eventSegment} {accountSegment}. {exceptionSegment}");
27+
}
28+
return formattedMessage;
29+
});
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)