Name: serilog-filters-expressions
Owner: Serilog
Description: Expression-based event filtering for Serilog
Created: 2017-01-03 09:37:55.0
Updated: 2018-05-09 05:56:32.0
Pushed: 2018-05-23 10:41:23.0
Homepage: https://serilog.net
Size: 83
Language: C#
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Expression-based event filtering for Serilog.
expr = "@Level = 'Information' and AppId is not null and Items[?] like 'C%'";
Logger = new LoggerConfiguration()
.Enrich.WithProperty("AppId", 10)
.Filter.ByIncludingOnly(expr)
.WriteTo.Console()
.CreateLogger();
rinted
Information("Cart contains {@Items}", new[] { "Tea", "Coffee" });
Information("Cart contains {@Items}", new[] { "Peanuts", "Chocolate" });
ot printed
Warning("Cart contains {@Items}", new[] { "Tea", "Coffee" });
Information("Cart contains {@Items}", new[] { "Apricots" });
CloseAndFlush();
Install Serilog.Filters.Expressions from NuGet:
all-Package Serilog.Filters.Expressions
Add Filter.ByIncludingOnly(fiterExpression)
or Filter.ByExcluding(fiterExpression)
calls to LoggerConfiguration
.
The syntax is based on SQL, with added support for object structures, arrays, and regular expressions.
| Category | Examples |
| :— | :— |
| Literals | 123
, 123.4
, 'Hello'
, true
, false
, null
|
| Properties | A
, A.B
, @Level
, @Timestamp
, @Exception
, @Message
, @MessageTemplate
, @Properties['A-b-c']
|
| Comparisons | A = B
, A <> B
, A > B
, A >= B
, A is null
, A is not null
, A in [1, 2]
|
| Text | A like 'H%'
, A not like 'H%'
, A like 'Hel_o'
, Contains(A, 'H')
, StartsWith(A, 'H')
, EndsWith(A, 'H')
, IndexOf(A, 'H')
, Length(A)
|
| Regular expressions | A = /H.*o/
, Contains(A, /[lL]/)
, other string functions |
| Collections | A[0] = 'Hello'
, A[?] = 'Hello'
(any), StartsWith(A[*], 'H')
(all), Length(A)
|
| Maths | A + 2
, A - 2
, A * 2
, A % 2
|
| Logic | not A
, A and B
, A or B
|
| Grouping | A * (B + C)
|
| Other | Has(A)
, TypeOf(A)
|
Note, the syntax below depends on features in Serilog 2.4+.
dd key="serilog:using:FilterExpressions" value="Serilog.Filters.Expressions" />
dd key="serilog:filter:ByExcluding.expression" value="Name = 'World'" />