forked from 47-studio-org/PostSharp.Samples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathServiceStackLogRecordBuilder.cs
87 lines (74 loc) · 1.9 KB
/
ServiceStackLogRecordBuilder.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
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
using PostSharp.Patterns.Diagnostics;
using PostSharp.Patterns.Diagnostics.Backends;
using PostSharp.Patterns.Diagnostics.RecordBuilders;
using PostSharp.Patterns.Formatters;
namespace PostSharp.Samples.Logging.CustomBackend.ServiceStack
{
public class ServiceStackLogRecordBuilder : TextLogRecordBuilder
{
public ServiceStackLogRecordBuilder(TextLoggingBackend backend) : base(backend)
{
}
protected override void Write(UnsafeString message)
{
var log = ((ServiceStackLoggingTypeSource) TypeSource).Log;
var messageString = message.ToString();
switch (Level)
{
case LogLevel.None:
break;
case LogLevel.Trace:
case LogLevel.Debug:
if (Exception == null)
{
log.Debug(messageString);
}
else
{
log.Debug(messageString, Exception);
}
break;
case LogLevel.Info:
if (Exception == null)
{
log.Info(messageString);
}
else
{
log.Info(messageString, Exception);
}
break;
case LogLevel.Warning:
if (Exception == null)
{
log.Warn(messageString);
}
else
{
log.Warn(messageString, Exception);
}
break;
case LogLevel.Error:
if (Exception == null)
{
log.Error(messageString);
}
else
{
log.Error(messageString, Exception);
}
break;
case LogLevel.Critical:
if (Exception == null)
{
log.Fatal(messageString);
}
else
{
log.Fatal(messageString, Exception);
}
break;
}
}
}
}