This repository was archived by the owner on May 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFleckLog.cs
More file actions
92 lines (79 loc) · 1.96 KB
/
FleckLog.cs
File metadata and controls
92 lines (79 loc) · 1.96 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Diagnostics;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
namespace Fleck
{
public class FleckLog
{
static ILogger _Logger = null;
internal static ILogger Logger
{
get
{
return FleckLog._Logger ?? (FleckLog._Logger = Fleck.Logger.CreateLogger<WebSocketServer>());
}
}
public static void Trace(string message, Exception ex = null)
{
FleckLog.Logger.LogTrace(ex, message);
}
public static void Info(string message, Exception ex = null)
{
FleckLog.Logger.LogInformation(ex, message);
}
public static void Warn(string message, Exception ex = null)
{
FleckLog.Logger.LogWarning(ex, message);
}
public static void Debug(string message, Exception ex = null)
{
FleckLog.Logger.LogDebug(ex, message);
}
public static void Error(string message, Exception ex = null)
{
FleckLog.Logger.LogError(ex, message);
}
}
#region Logger
public static class Logger
{
static ILoggerFactory LoggerFactory;
/// <summary>
/// Assigns a logger factory
/// </summary>
/// <param name="loggerFactory"></param>
public static void AssignLoggerFactory(ILoggerFactory loggerFactory)
{
if (Logger.LoggerFactory == null && loggerFactory != null)
Logger.LoggerFactory = loggerFactory;
}
/// <summary>
/// Gets a logger factory
/// </summary>
/// <returns></returns>
public static ILoggerFactory GetLoggerFactory()
{
return Logger.LoggerFactory ?? new NullLoggerFactory();
}
/// <summary>
/// Creates a logger
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public static ILogger CreateLogger(Type type)
{
return Logger.GetLoggerFactory().CreateLogger(type);
}
/// <summary>
/// Creates a logger
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static ILogger CreateLogger<T>()
{
return Logger.CreateLogger(typeof(T));
}
}
#endregion
}