|
1 |
| -# _Serilog Expressions_ |
| 1 | +# _Serilog Expressions_ [](https://ci.appveyor.com/project/NicholasBlumhardt/serilog-expressions/branch/dev) |
2 | 2 |
|
3 | 3 | An embeddable mini-language for filtering, enriching, and formatting Serilog
|
4 | 4 | events, ideal for use with JSON or XML configuration.
|
@@ -178,21 +178,37 @@ StartsWith(User.Name, 'n') ci
|
178 | 178 | **Trim down `SourceContext` to a type name only:**
|
179 | 179 |
|
180 | 180 | ```
|
181 |
| -coalesce(Substring(SourceContext, LastIndexOf(SourceContext, '.') + 1), SourceContext, '<no source>') |
| 181 | +Substring(SourceContext, LastIndexOf(SourceContext, '.') + 1) |
182 | 182 | ```
|
183 | 183 |
|
| 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 | + |
184 | 186 | **Access a property with a non-identifier name:**
|
185 | 187 |
|
186 | 188 | ```
|
187 | 189 | @p['some name']
|
188 | 190 | ```
|
189 | 191 |
|
| 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 | + |
190 | 194 | **Access a property with inconsistent casing:**
|
191 | 195 |
|
192 | 196 | ```
|
193 | 197 | ElementAt(@p, 'someName') ci
|
194 | 198 | ```
|
195 | 199 |
|
| 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 | + |
196 | 212 | ## Working with the raw API
|
197 | 213 |
|
198 | 214 | The package provides the class `SerilogExpression` in the `Serilog.Expressions` namespace
|
|
0 commit comments