Skip to content

Commit ad21c55

Browse files
committed
Implemented default logger formatter
#59
1 parent e10f2ed commit ad21c55

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using Microsoft.Extensions.Logging;
3+
4+
namespace Splunk
5+
{
6+
public class BasicLoggerFormatter : ILoggerFormatter
7+
{
8+
public string Format<T>(string categoryName, LogLevel logLevel, EventId eventId, T state, Exception exception)
9+
{
10+
return string.Format("{0}: [{1}] [{2}:{3}] {4} {5}",
11+
categoryName,
12+
logLevel.ToString(),
13+
eventId.Id,
14+
eventId.Name,
15+
state != null ? state.ToString() : string.Empty,
16+
exception != null ? exception.ToString() : string.Empty);
17+
}
18+
19+
public SplunkJSONEntry FormatJson<T>(string categoryName, LogLevel logLevel, EventId eventId, T state, Exception exception)
20+
{
21+
string eventText = Format(categoryName, logLevel, eventId, state, exception);
22+
return new SplunkJSONEntry(eventText);
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)