-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathLogger.cs
50 lines (42 loc) · 1.24 KB
/
Logger.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
45
46
47
48
49
50
using System.Collections.Generic;
using System.Diagnostics;
using Coflnet;
using Microsoft.Extensions.Logging;
namespace dev
{
public class Logger
{
public static Logger Instance { get; }
public static ILoggerFactory Factory { get; }
static Logger()
{
Instance = new Logger();
Factory = LoggerFactory.Create(b => b.AddConsole());
}
public void Log(string message)
{
System.Console.WriteLine("Info: " + message);
LogToActivity(message);
}
public void Error(string message)
{
System.Console.WriteLine("Error: " + message);
LogToActivity(message);
Activity.Current?.SetTag("error", true);
}
private static void LogToActivity(string message)
{
Activity.Current?.AddEvent(new("log", default, new(new Dictionary<string, object> { { "message", message } })));
}
public void Info(string message)
{
Log(message);
}
public void Error(System.Exception error, string message = null)
{
if (message != null)
Error(message);
Error(error.ToString());
}
}
}