forked from KuraiAndras/Serilog.Sinks.Unity3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnity3DLogEventSink.cs
44 lines (37 loc) · 1.3 KB
/
Unity3DLogEventSink.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using Serilog.Core;
using Serilog.Events;
using Serilog.Formatting;
using System;
using System.IO;
using UnityEngine;
namespace Serilog.Sinks.Unity3D
{
public sealed class Unity3DLogEventSink : ILogEventSink
{
private readonly ITextFormatter _formatter;
public Unity3DLogEventSink(ITextFormatter formatter) => _formatter = formatter;
public void Emit(LogEvent logEvent)
{
using (var buffer = new StringWriter())
{
_formatter.Format(logEvent, buffer);
switch (logEvent.Level)
{
case LogEventLevel.Verbose:
case LogEventLevel.Debug:
case LogEventLevel.Information:
Debug.Log(buffer.ToString().Trim());
break;
case LogEventLevel.Warning:
Debug.LogWarning(buffer.ToString().Trim());
break;
case LogEventLevel.Error:
case LogEventLevel.Fatal:
Debug.LogError(buffer.ToString().Trim());
break;
default: throw new ArgumentOutOfRangeException(nameof(logEvent.Level), "Unknown log level");
}
}
}
}
}