forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestLogProvider.cs
More file actions
58 lines (48 loc) · 1.43 KB
/
TestLogProvider.cs
File metadata and controls
58 lines (48 loc) · 1.43 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
using System;
using System.Globalization;
using System.Text;
namespace ScriptCs.Tests
{
using ScriptCs.Contracts;
public class TestLogProvider : ILogProvider
{
private static readonly Disposable disposable = new Disposable();
private readonly StringBuilder _output = new StringBuilder();
public string Output
{
get { return _output.ToString(); }
}
public Logger GetLogger(string name)
{
return Log;
}
public IDisposable OpenNestedContext(string message)
{
return disposable;
}
public IDisposable OpenMappedContext(string key, string value)
{
return disposable;
}
private bool Log(
LogLevel logLevel, Func<string> messageFunc, Exception exception = null, params object[] formatParameters)
{
if (messageFunc != null)
{
var line = string.Format(
CultureInfo.InvariantCulture,
"{0}: {1}",
logLevel.ToString().ToUpper(),
string.Format(CultureInfo.InvariantCulture, messageFunc(), formatParameters));
_output.AppendLine(line);
}
return true;
}
private sealed class Disposable : IDisposable
{
public void Dispose()
{
}
}
}
}