forked from destructurama/attributed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogWithNameAttributedTests.cs
45 lines (37 loc) · 1.18 KB
/
LogWithNameAttributedTests.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
using Destructurama.Attributed.Tests.Support;
using NUnit.Framework;
using Serilog;
using Serilog.Events;
using System.Linq;
namespace Destructurama.Attributed.Tests
{
[TestFixture]
public class LogWithNameAttributedTests
{
[Test]
public void AttributesAreConsultedWhenDestructuring()
{
LogEvent evt = null!;
var log = new LoggerConfiguration()
.Destructure.UsingAttributes()
.WriteTo.Sink(new DelegatingSink(e => evt = e))
.CreateLogger();
var personalData = new PersonalData
{
Name = "John Doe"
};
log.Information("Here is {@PersonData}", personalData);
var sv = (StructureValue)evt.Properties["PersonData"];
var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value);
var literalValue = props["FullName"].LiteralValue();
Assert.AreEqual("John Doe", literalValue);
}
#region LogWithName
public class PersonalData
{
[LogWithName("FullName")]
public string? Name { get; set; }
}
#endregion
}
}