Skip to content

Commit c7f6811

Browse files
committed
Publishing key
1 parent 9eb64ef commit c7f6811

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# _Serilog Expressions_
1+
# _Serilog Expressions_ [![Build status](https://ci.appveyor.com/api/projects/status/2wg3tsdybwmf8tp1/branch/dev?svg=true)](https://ci.appveyor.com/project/NicholasBlumhardt/serilog-expressions/branch/dev)
22

33
An embeddable mini-language for filtering, enriching, and formatting Serilog
44
events, ideal for use with JSON or XML configuration.
@@ -178,21 +178,37 @@ StartsWith(User.Name, 'n') ci
178178
**Trim down `SourceContext` to a type name only:**
179179

180180
```
181-
coalesce(Substring(SourceContext, LastIndexOf(SourceContext, '.') + 1), SourceContext, '<no source>')
181+
Substring(SourceContext, LastIndexOf(SourceContext, '.') + 1)
182182
```
183183

184+
This expression takes advantage of `LastIndexOf()` returning -1 when no `.` character appears in `SourceContext`, to yield a `startIndex` of 0 in that case.
185+
184186
**Access a property with a non-identifier name:**
185187

186188
```
187189
@p['some name']
188190
```
189191

192+
Any structured value, including the built-in `@p`, can be indexed by string key. This means that `User.Name` and `User['Name']` are equivalent, for example.
193+
190194
**Access a property with inconsistent casing:**
191195

192196
```
193197
ElementAt(@p, 'someName') ci
194198
```
195199

200+
`ElementAt()` is a function-call version of the `[]` indexer notation, which means it can accept the `ci` case-insensitivity modifier.
201+
202+
**Format events as newline-delimited JSON (template, embedded in C# or JSON):**
203+
204+
```
205+
{ {Timestamp: @t, Username: User.Name} }\n
206+
```
207+
208+
This output template shows the use of a space between the opening `{` of a hole, and the enclosed object literal with `Timestamp` and
209+
`Username` fields. The object will be formatted as JSON. The trailing `\n` is a C# or JSON newline literal (don't escape this any further, as
210+
it's not part of the output template syntax).
211+
196212
## Working with the raw API
197213

198214
The package provides the class `SerilogExpression` in the `Serilog.Expressions` namespace

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ deploy:
1414
branch: /^(main|dev)$/
1515
- provider: GitHub
1616
auth_token:
17-
secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX
17+
secure: 3IDqxoOvib3PQmutXd+ebge6G7aLsZ34xZHxJtYpUsQYOVNKdTfsrs7ChEe2sbPY
1818
artifact: /Serilog.*\.nupkg/
1919
tag: v$(appveyor_build_version)
2020
on:

example/Sample/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static void Main()
1515
using var log = new LoggerConfiguration()
1616
.Enrich.WithProperty("AppId", 10)
1717
.Enrich.WithComputed("FirstItem", "Items[0]")
18-
.Enrich.WithComputed("SourceContext", "coalesce(Substring(SourceContext, LastIndexOf(SourceContext, '.') + 1), SourceContext, '<no source>')")
18+
.Enrich.WithComputed("SourceContext", "coalesce(Substring(SourceContext, LastIndexOf(SourceContext, '.') + 1), '<no source>')")
1919
.Filter.ByIncludingOnly("@l = 'Information' and AppId is not null and Items[?] like 'C%'")
2020
.WriteTo.Console(outputTemplate:
2121
"[{Timestamp:HH:mm:ss} {Level:u3} ({SourceContext})] {Message:lj} (first item is {FirstItem}){NewLine}{Exception}")

0 commit comments

Comments
 (0)