Skip to content

Commit 0b91241

Browse files
committed
Use CLEF names for built-in properties
1 parent f223c27 commit 0b91241

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

example/Sample/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
namespace Sample
77
{
8+
// ReSharper disable once ClassNeverInstantiated.Global
89
public class Program
910
{
1011
public static void Main()
1112
{
1213
SelfLog.Enable(Console.Error);
1314

14-
const string expr = "@Level = 'Information' and AppId is not null and Items[?] like 'C%'";
15+
const string expr = "@l = 'Information' and AppId is not null and Items[?] like 'C%'";
1516

1617
using var log = new LoggerConfiguration()
1718
.Enrich.WithProperty("AppId", 10)
@@ -21,7 +22,7 @@ public static void Main()
2122
.WriteTo.Console(outputTemplate:
2223
"[{Timestamp:HH:mm:ss} {Level:u3} ({SourceContext})] {Message:lj} (first item is {FirstItem}){NewLine}{Exception}")
2324
.WriteTo.Console(new OutputTemplate(
24-
"[{@Timestamp} {@Level} ({SourceContext})] {@Message} (first item is {Items[0]})\n{@Exception}"))
25+
"[{@t} {@l} ({SourceContext})] {@m} (first item is {Items[0]})\n{@x}"))
2526
.CreateLogger();
2627

2728
log.ForContext<Program>().Information("Cart contains {@Items}", new[] { "Tea", "Coffee" });

src/Serilog.Expressions/Expressions/BuiltInProperty.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ namespace Serilog.Expressions
22
{
33
static class BuiltInProperty
44
{
5-
public const string Exception = "Exception";
6-
public const string Level = "Level";
7-
public const string Timestamp = "Timestamp";
8-
public const string Message = "Message";
9-
public const string MessageTemplate = "MessageTemplate";
10-
public const string Properties = "Properties";
5+
public const string Exception = "x";
6+
public const string Level = "l";
7+
public const string Timestamp = "t";
8+
public const string Message = "m";
9+
public const string MessageTemplate = "mt";
10+
public const string Properties = "p";
11+
12+
// Undocumented, simplifies a few scenarios; an `undefined()` may be better.
1113
public const string Undefined = "Undefined";
1214
}
1315
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
// Temporarily using Serilog's default value formatting
2-
Hello, {'world'}! ⇶ Hello, "world"!
3-
{@Level} ⇶ "Information"
2+
Hello, {'world'}! ⇶ Hello, world!
3+
{@l} ⇶ Information
4+
Items are {[1, 2]} ⇶ Items are [1,2]
5+
{@p} ⇶ {}

test/Serilog.Expressions.Tests/ExpressionCompilerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void ExpressionsEvaluateWildcardsOnCollectionItems()
7878
[Fact]
7979
public void ExpressionsEvaluateBuiltInProperties()
8080
{
81-
AssertEvaluation("@Level = 'Information'",
81+
AssertEvaluation("@l = 'Information'",
8282
Some.InformationEvent(),
8383
Some.WarningEvent());
8484
}
@@ -121,7 +121,7 @@ public void SequenceLengthCanBeDetermined()
121121
[Fact]
122122
public void InMatchesLiterals()
123123
{
124-
AssertEvaluation("@Level in ['Warning', 'Error']",
124+
AssertEvaluation("@l in ['Warning', 'Error']",
125125
Some.LogEvent(LogEventLevel.Error, "Hello"),
126126
Some.InformationEvent("Hello"));
127127
}

0 commit comments

Comments
 (0)