-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMessageFormatter.cs
More file actions
24 lines (21 loc) · 920 Bytes
/
MessageFormatter.cs
File metadata and controls
24 lines (21 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System;
using System.Linq;
using Microsoft.Extensions.Logging;
namespace Ultz.Extensions.Logging
{
public sealed class MessageFormatter : IMessageFormatter
{
public static readonly IMessageFormatter Default = new MessageFormatter();
private MessageFormatter()
{
// do nothing, just want this private
}
public string Format<TState>(string name, LogLevel logLevel, EventId eventId, TState state, Exception exception,
Func<TState, Exception, string> formatter, UltzLoggerProvider loggerProvider) =>
string.Join("\n", formatter(state, exception).Split('\n').Select(x =>
string.Format(loggerProvider.MessageFormat,
name,
loggerProvider.LogLevelStrings[logLevel], x, eventId,
UltzLoggerProvider.GetSyslogSeverityString(logLevel), DateTime.Now)));
}
}