-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSerilogUnitySink.cs
42 lines (39 loc) · 1.09 KB
/
SerilogUnitySink.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
using Serilog;
using Serilog.Configuration;
using Serilog.Core;
using Serilog.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace RSG
{
/// <summary>
/// Serilog sink that writes to Unity log.
/// </summary>
[SerilogSink]
internal class SerilogUnitySink : ILogEventSink
{
/// <summary>
/// A tag that identifies RSG log messages that have been passed to Unity.
/// </summary>
public static readonly string RSGLogTag = "[RSG]: ";
public void Emit(LogEvent logEvent)
{
var msg = RSGLogTag + logEvent.RenderMessage();
if (logEvent.Level == LogEventLevel.Error || logEvent.Level == LogEventLevel.Fatal)
{
Debug.LogError(msg);
}
else if (logEvent.Level == LogEventLevel.Warning)
{
Debug.LogWarning(msg);
}
else
{
Debug.Log(msg);
}
}
}
}