forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetCoreLogFactory.cs
More file actions
120 lines (96 loc) · 2.93 KB
/
NetCoreLogFactory.cs
File metadata and controls
120 lines (96 loc) · 2.93 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#if NETSTANDARD1_6
using System;
using ServiceStack.Logging;
using Microsoft.Extensions.Logging;
namespace ServiceStack.NetCore
{
public class NetCoreLogFactory : ILogFactory
{
ILoggerFactory loggerFactory;
private bool debugEnabled;
public NetCoreLogFactory(ILoggerFactory loggerFactory, bool debugEnabled=false)
{
this.loggerFactory = loggerFactory;
this.debugEnabled = debugEnabled;
}
public ILog GetLogger(Type type)
{
return new NetCoreLog(loggerFactory.CreateLogger(type), debugEnabled);
}
public ILog GetLogger(string typeName)
{
return new NetCoreLog(loggerFactory.CreateLogger(typeName), debugEnabled);
}
}
public class NetCoreLog : ILog
{
private ILogger log;
public NetCoreLog(ILogger logger, bool debugEnabled=false)
{
this.log = logger;
this.IsDebugEnabled = debugEnabled;
}
public bool IsDebugEnabled { get; }
public void Debug(object message)
{
log.LogDebug(message.ToString());
}
public void Debug(object message, Exception exception)
{
log.LogDebug(message.ToString(), exception);
}
public void DebugFormat(string format, params object[] args)
{
log.LogDebug(format, args);
}
public void Error(object message)
{
log.LogError(message.ToString());
}
public void Error(object message, Exception exception)
{
log.LogError(message.ToString(), exception);
}
public void ErrorFormat(string format, params object[] args)
{
log.LogError(format, args);
}
public void Fatal(object message)
{
log.LogCritical(message.ToString());
}
public void Fatal(object message, Exception exception)
{
log.LogCritical(message.ToString(), exception);
}
public void FatalFormat(string format, params object[] args)
{
log.LogCritical(format, args);
}
public void Info(object message)
{
log.LogInformation(message.ToString());
}
public void Info(object message, Exception exception)
{
log.LogInformation(message.ToString(), exception);
}
public void InfoFormat(string format, params object[] args)
{
log.LogInformation(format, args);
}
public void Warn(object message)
{
log.LogWarning(message.ToString());
}
public void Warn(object message, Exception exception)
{
log.LogWarning(message.ToString(), exception);
}
public void WarnFormat(string format, params object[] args)
{
log.LogWarning(format, args);
}
}
}
#endif