-
Notifications
You must be signed in to change notification settings - Fork 30
/
Snippets.cs
81 lines (63 loc) · 1.71 KB
/
Snippets.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
using System;
using System.Diagnostics.CodeAnalysis;
using NUnit.Framework;
using ZeroLog.Appenders;
using ZeroLog.Configuration;
namespace ZeroLog.Tests;
[TestFixture]
public class Snippets
{
#region GetLogger
private static readonly Log _log = LogManager.GetLogger(typeof(YourClass));
#endregion
[SuppressMessage("ReSharper", "UnusedMember.Local")]
private static void Init()
{
#region Initialize
LogManager.Initialize(new ZeroLogConfiguration
{
RootLogger =
{
Appenders =
{
new ConsoleAppender()
}
}
});
#endregion
}
[Test]
public void StringInterpolationApi()
{
#region StringInterpolationApi
var date = DateTime.Today.AddDays(1);
_log.Info($"Tomorrow ({date:yyyy-MM-dd}) will be in {GetNumberOfSecondsUntilTomorrow():N0} seconds.");
#endregion
}
[Test]
public void StringBuilderApi()
{
#region StringBuilderApi
_log.Info()
.Append("Tomorrow (")
.Append(DateTime.Today.AddDays(1), "yyyy-MM-dd")
.Append(") will be in ")
.Append(GetNumberOfSecondsUntilTomorrow(), "N0")
.Append(" seconds.")
.Log();
#endregion
}
[Test]
public void StructuredData()
{
#region StructuredData
_log.Info()
.Append("Tomorrow is another day.")
.AppendKeyValue("NumSecondsUntilTomorrow", GetNumberOfSecondsUntilTomorrow())
.Log();
#endregion
}
private static int GetNumberOfSecondsUntilTomorrow()
=> 10;
private class YourClass;
}