Skip to content

Commit 1685461

Browse files
authored
Merge pull request #101 from serilog/dev
3.5.0 Release
2 parents 25c6509 + 7b6aab2 commit 1685461

File tree

6 files changed

+27
-22
lines changed

6 files changed

+27
-22
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ User-defined functions are supplied through an instance of `NameResolver`:
387387

388388
```csharp
389389
var myFunctions = new StaticMemberNameResolver(typeof(MyFunctions));
390-
var expr = SerilogExpression.Compile("IsHello(User.Name)", nameResolver: customSerilogFunctions);
390+
var expr = SerilogExpression.Compile("IsHello(User.Name)", nameResolver: myFunctions);
391391
// Filter events based on whether `User.Name` is `'Hello'` :-)
392392
```
393393

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ artifacts:
88
deploy:
99
- provider: NuGet
1010
api_key:
11-
secure: xIn2Dlahvk1QLaFAazCkjSc83UC1Uv5jeMeyA2NDDiLeHZwFqMm5da6nHEzm6ks5
11+
secure: AcMGMnsJdQe1+SQwf+9VpRqcKNw93zr96OlxAEmPob52vqxDNH844SmdYidGX0cL
1212
skip_symbols: true
1313
on:
1414
branch: /^(main|dev)$/

src/Serilog.Expressions/Serilog.Expressions.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<Description>An embeddable mini-language for filtering, enriching, and formatting Serilog
55
events, ideal for use with JSON or XML configuration.</Description>
6-
<VersionPrefix>3.4.1</VersionPrefix>
6+
<VersionPrefix>3.5.0</VersionPrefix>
77
<Authors>Serilog Contributors</Authors>
88
<TargetFrameworks>netstandard2.0;netstandard2.1;net5.0</TargetFrameworks>
99
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@@ -17,7 +17,7 @@
1717
</PropertyGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Serilog" Version="2.10.0" />
20+
<PackageReference Include="Serilog" Version="2.12.0" />
2121
<PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="All" />
2222
</ItemGroup>
2323

src/Serilog.Expressions/Templates/Compilation/CompiledRepetition.cs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ class CompiledRepetition : CompiledTemplate
2222
{
2323
readonly Evaluatable _enumerable;
2424
readonly string? _keyOrElementName;
25-
readonly string? _valueName;
25+
readonly string? _valueOrIndexName;
2626
readonly CompiledTemplate _body;
2727
readonly CompiledTemplate? _delimiter;
2828
readonly CompiledTemplate? _alternative;
2929

3030
public CompiledRepetition(
3131
Evaluatable enumerable,
3232
string? keyOrElementName,
33-
string? valueName,
33+
string? valueOrIndexName,
3434
CompiledTemplate body,
3535
CompiledTemplate? delimiter,
3636
CompiledTemplate? alternative)
3737
{
3838
_enumerable = enumerable;
3939
_keyOrElementName = keyOrElementName;
40-
_valueName = valueName;
40+
_valueOrIndexName = valueOrIndexName;
4141
_body = body;
4242
_delimiter = delimiter;
4343
_alternative = alternative;
@@ -52,29 +52,32 @@ public override void Evaluate(EvaluationContext ctx, TextWriter output)
5252
return;
5353
}
5454

55-
if (enumerable is SequenceValue sv)
55+
if (enumerable is SequenceValue sequence)
5656
{
57-
if (sv.Elements.Count == 0)
57+
if (sequence.Elements.Count == 0)
5858
{
5959
_alternative?.Evaluate(ctx, output);
6060
return;
6161
}
6262

63-
var first = true;
64-
foreach (var element in sv.Elements)
63+
for (var i = 0; i < sequence.Elements.Count; ++i)
6564
{
66-
if (element == null)
67-
continue; // Should have been invalid but Serilog didn't check and so this does occur in the wild.
65+
// Null elements should have been invalid but Serilog didn't check, and so this does occur in the wild.
66+
var element = sequence.Elements[i] ?? new ScalarValue(null);
6867

69-
if (first)
70-
first = false;
71-
else
68+
if (i != 0)
69+
{
7270
_delimiter?.Evaluate(ctx, output);
71+
}
7372

7473
var local = _keyOrElementName != null
75-
? new(ctx.LogEvent, Locals.Set(ctx.Locals, _keyOrElementName, element))
74+
? new EvaluationContext(ctx.LogEvent, Locals.Set(ctx.Locals, _keyOrElementName, element))
7675
: ctx;
7776

77+
local = _valueOrIndexName != null
78+
? new EvaluationContext(local.LogEvent, Locals.Set(local.Locals, _valueOrIndexName, new ScalarValue(i)))
79+
: local;
80+
7881
_body.Evaluate(local, output);
7982
}
8083

@@ -101,8 +104,8 @@ public override void Evaluate(EvaluationContext ctx, TextWriter output)
101104
? new(ctx.LogEvent, Locals.Set(ctx.Locals, _keyOrElementName, new ScalarValue(member.Name)))
102105
: ctx;
103106

104-
local = _valueName != null
105-
? new(local.LogEvent, Locals.Set(local.Locals, _valueName, member.Value))
107+
local = _valueOrIndexName != null
108+
? new(local.LogEvent, Locals.Set(local.Locals, _valueOrIndexName, member.Value))
106109
: local;
107110

108111
_body.Evaluate(local, output);
@@ -129,8 +132,8 @@ public override void Evaluate(EvaluationContext ctx, TextWriter output)
129132
? new(ctx.LogEvent, Locals.Set(ctx.Locals, _keyOrElementName, element.Key))
130133
: ctx;
131134

132-
local = _valueName != null
133-
? new(local.LogEvent, Locals.Set(local.Locals, _valueName, element.Value))
135+
local = _valueOrIndexName != null
136+
? new(local.LogEvent, Locals.Set(local.Locals, _valueOrIndexName, element.Value))
134137
: local;
135138

136139
_body.Evaluate(local, output);

src/Serilog.Expressions/Templates/Compilation/NameResolution/TemplateLocalNameResolver.cs renamed to src/Serilog.Expressions/Templates/Compilation/NameResolution/TemplateLocalNameBinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Template Transform(Repetition rep, Stack<string> locals)
7676
locals.Pop();
7777

7878
return new Repetition(
79-
rep.Enumerable,
79+
ExpressionLocalNameBinder.BindLocalValueNames(rep.Enumerable, locals),
8080
rep.BindingNames,
8181
body,
8282
rep.Delimiter != null ? Transform(rep.Delimiter, locals) : null,

test/Serilog.Expressions.Tests/Cases/template-evaluation-cases.asv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ A{#if false}B{#else if false}C{#else if true}D{#else}E{#end} ⇶ AD
2323
A{#if false}B{#else if true}C{#end} ⇶ AC
2424
{#if true}A{#if false}B{#else}C{#end}D{#end} ⇶ ACD
2525
{#each a in [1,2,3]}<{a}>{#delimit},{#end} ⇶ <1>,<2>,<3>
26+
{#each a, i in [1,2,3]}<{a}>({i}){#delimit},{#end} ⇶ <1>(0),<2>(1),<3>(2)
2627
{#each a in {x: 1, y: 2}}{a}{#end} ⇶ xy
2728
{#each a, b in {x: 1, y: 2}}{a}.{b}{#end} ⇶ x.1y.2
29+
{#each a, b in {x: {y: 'z'}}}{#each c, d in b}A: {a}, C: {c}, D: {d}{#end}{#end} ⇶ A: x, C: y, D: z
2830
{#if true}A{#each a in [1]}B{a}{#end}C{#end}D ⇶ AB1CD
2931
{#each a in []}{a}!{#else}none{#end} ⇶ none
3032
Culture-specific {42.34} ⇶ Culture-specific 42,34

0 commit comments

Comments
 (0)