Skip to content
This repository was archived by the owner on Feb 27, 2022. It is now read-only.

Commit a95da57

Browse files
authored
Merge pull request #3 from serilog/dev
1.0.0 Release
2 parents 0378004 + 6b0778b commit a95da57

File tree

82 files changed

+3988
-23
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+3988
-23
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Auto detect text files and perform LF normalization
2+
3+
* text=auto

.gitignore

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ x86/
2020
bld/
2121
[Bb]in/
2222
[Oo]bj/
23-
[Ll]og/
2423

2524
# Visual Studio 2015 cache/options directory
2625
.vs/
@@ -80,8 +79,6 @@ ipch/
8079
*.opensdf
8180
*.sdf
8281
*.cachefile
83-
*.VC.db
84-
*.VC.VC.opendb
8582

8683
# Visual Studio profiler
8784
*.psess
@@ -140,16 +137,11 @@ publish/
140137
# Publish Web Output
141138
*.[Pp]ublish.xml
142139
*.azurePubxml
143-
# TODO: Comment the next line if you want to checkin your web deploy settings
140+
# TODO: Comment the next line if you want to checkin your web deploy settings
144141
# but database connection strings (with potential passwords) will be unencrypted
145142
*.pubxml
146143
*.publishproj
147144

148-
# Microsoft Azure Web App publish settings. Comment the next line if you want to
149-
# checkin your Azure Web App publish settings, but sensitive information contained
150-
# in these scripts will be unencrypted
151-
PublishScripts/
152-
153145
# NuGet Packages
154146
*.nupkg
155147
# The packages folder can be ignored because of Package Restore
@@ -170,11 +162,12 @@ csx/
170162
ecf/
171163
rcf/
172164

173-
# Windows Store app package directories and files
165+
# Microsoft Azure ApplicationInsights config file
166+
ApplicationInsights.config
167+
168+
# Windows Store app package directory
174169
AppPackages/
175170
BundleArtifacts/
176-
Package.StoreAssociation.xml
177-
_pkginfo.txt
178171

179172
# Visual Studio cache files
180173
# files ending in .cache can be ignored
@@ -193,10 +186,6 @@ ClientBin/
193186
node_modules/
194187
orleans.codegen.cs
195188

196-
# Since there are multiple workflows, uncomment next line to ignore bower_components
197-
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
198-
#bower_components/
199-
200189
# RIA/Silverlight projects
201190
Generated_Code/
202191

@@ -242,11 +231,8 @@ _Pvt_Extensions
242231

243232
# Paket dependency manager
244233
.paket/paket.exe
245-
paket-files/
246234

247235
# FAKE - F# Make
248236
.fake/
249-
250-
# JetBrains Rider
251-
.idea/
252-
*.sln.iml
237+
example/Sample/log.txt
238+
BenchmarkDotNet.Artifacts/

Build.ps1

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
echo "build: Build started"
2+
3+
Push-Location $PSScriptRoot
4+
5+
if(Test-Path .\artifacts) {
6+
echo "build: Cleaning .\artifacts"
7+
Remove-Item .\artifacts -Force -Recurse
8+
}
9+
10+
& dotnet restore --no-cache
11+
12+
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
13+
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
14+
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"]
15+
16+
echo "build: Version suffix is $suffix"
17+
18+
foreach ($src in ls src/*) {
19+
Push-Location $src
20+
21+
echo "build: Packaging project in $src"
22+
23+
& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix
24+
if($LASTEXITCODE -ne 0) { exit 1 }
25+
26+
Pop-Location
27+
}
28+
29+
foreach ($test in ls test/*.PerformanceTests) {
30+
Push-Location $test
31+
32+
echo "build: Building performance test project in $test"
33+
34+
& dotnet build -c Release
35+
if($LASTEXITCODE -ne 0) { exit 2 }
36+
37+
Pop-Location
38+
}
39+
40+
foreach ($test in ls test/*.Tests) {
41+
Push-Location $test
42+
43+
echo "build: Testing project in $test"
44+
45+
& dotnet test -c Release
46+
if($LASTEXITCODE -ne 0) { exit 3 }
47+
48+
Pop-Location
49+
}
50+
51+
Pop-Location

README.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,61 @@
1-
# Serilog.Filters.Expressions
2-
Expression-based event filtering for Serilog.
1+
# Serilog.Filters.Expressions [![Build status](https://ci.appveyor.com/api/projects/status/wnh0ig2udlld9oe4?svg=true)](https://ci.appveyor.com/project/serilog/serilog-filters-expressions) [![NuGet Pre Release](https://img.shields.io/nuget/vpre/Serilog.Filters.Expressions.svg)](https://nuget.org/packages/serilog.filters.expressions)
2+
3+
Expression-based event filtering for [Serilog](https://serilog.net).
4+
5+
```csharp
6+
var expr = "@Level = 'Information' and AppId is not null and Items[?] like 'C%'";
7+
8+
Log.Logger = new LoggerConfiguration()
9+
.Enrich.WithProperty("AppId", 10)
10+
.Filter.ByIncludingOnly(expr)
11+
.WriteTo.LiterateConsole()
12+
.CreateLogger();
13+
14+
// Printed
15+
Log.Information("Cart contains {@Items}", new[] { "Tea", "Coffee" });
16+
Log.Information("Cart contains {@Items}", new[] { "Peanuts", "Chocolate" });
17+
18+
// Not printed
19+
Log.Warning("Cart contains {@Items}", new[] { "Tea", "Coffee" });
20+
Log.Information("Cart contains {@Items}", new[] { "Apricots" });
21+
22+
Log.CloseAndFlush();
23+
```
24+
25+
### Getting started
26+
27+
Install _Serilog.Filters.Expressions_ from NuGet:
28+
29+
```powershell
30+
Install-Package Serilog.Filters.Expressions -Pre
31+
```
32+
33+
Add `Filter.ByIncludingOnly(fiterExpression)` or `Filter.ByExcluding(fiterExpression)` calls to `LoggerConfiguration`.
34+
35+
### Syntax
36+
37+
The syntax is based on SQL, with added support for object structures, arrays, and regular expressions.
38+
39+
| Category | Examples |
40+
| :--- | :--- |
41+
| **Literals** | `123`, `123.4`, `'Hello'`, `true`, `false`, `null` |
42+
| **Properties** | `A`, `A.B`, `@Level`, `@Timestamp`, `@Exception`, `@Message`, `@MessageTemplate`, `@Properties['A-b-c']` |
43+
| **Comparisons** | `A = B`, `A <> B`, `A > B`, `A >= B`, `A is null`, `A is not null` |
44+
| **Text** | `A like 'H%'`, `A not like 'H%'`, `A like 'Hel_o'`, `Contains(A, 'H')`, `StartsWith(A, 'H')`, `EndsWith(A, 'H')`, `IndexOf(A, 'H')` |
45+
| **Regular expressions** | `A = /H.*o/`, `Contains(A, /[lL]/)`, other string functions |
46+
| **Collections** | `A[0] = 'Hello'`, `A[?] = 'Hello'` (any), `StartsWith(A[*], 'H')` (all) |
47+
| **Maths** | `A + 2`, `A - 2`, `A * 2`, `A % 2` |
48+
| **Logic** | `not A`, `A and B`, `A or B` |
49+
| **Grouping** | `A * (B + C)` |
50+
| **Other** | `Has(A)`, `TypeOf(A)` |
51+
52+
### XML configuration
53+
54+
**Note, the syntax below depends on [an unreleased Serilog version](https://github.com/serilog/serilog/pull/925).**
55+
56+
```xml
57+
<add key="serilog:using:FilterExpressions" value="Serilog.Filters.Expressions" />
58+
<add key="serilog:Filter:ByExcluding.expression" value="Name = 'World'" />
59+
```
60+
61+

RunPerfTests.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Push-Location $PSScriptRoot
2+
3+
./Build.ps1
4+
5+
foreach ($test in ls test/*.PerformanceTests) {
6+
Push-Location $test
7+
8+
echo "perf: Running performance test project in $test"
9+
10+
& dotnet test -c Release
11+
if($LASTEXITCODE -ne 0) { exit 2 }
12+
13+
Pop-Location
14+
}
15+
16+
Pop-Location

appveyor.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
version: '{build}'
2+
skip_tags: true
3+
image: Visual Studio 2015
4+
configuration: Release
5+
install:
6+
- ps: mkdir -Force ".\build\" | Out-Null
7+
- ps: Invoke-WebRequest "https://rg.gosu.cc/dotnet/cli/rel/1.0.0-preview2/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1"
8+
- ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetcli"
9+
- ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 1.0.0-preview2-003131'
10+
- ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path"
11+
build_script:
12+
- ps: ./Build.ps1
13+
test: off
14+
artifacts:
15+
- path: artifacts/Serilog.*.nupkg
16+
deploy:
17+
- provider: NuGet
18+
api_key:
19+
secure: nvZ/z+pMS91b3kG4DgfES5AcmwwGoBYQxr9kp4XiJHj25SAlgdIxFx++1N0lFH2x
20+
skip_symbols: true
21+
on:
22+
branch: /^(master|dev)$/
23+
- provider: GitHub
24+
auth_token:
25+
secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX
26+
artifact: /Serilog.*\.nupkg/
27+
tag: v$(appveyor_build_version)
28+
on:
29+
branch: master

assets/Serilog.snk

596 Bytes
Binary file not shown.

example/Sample/Program.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Serilog;
2+
3+
namespace Sample
4+
{
5+
public class Program
6+
{
7+
public static void Main(string[] args)
8+
{
9+
var expr = "@Level = 'Information' and AppId is not null and Items[?] like 'C%'";
10+
11+
Log.Logger = new LoggerConfiguration()
12+
.Enrich.WithProperty("AppId", 10)
13+
.Filter.ByIncludingOnly(expr)
14+
.WriteTo.LiterateConsole()
15+
.CreateLogger();
16+
17+
Log.Information("Cart contains {@Items}", new[] { "Tea", "Coffee" });
18+
Log.Warning("Cart contains {@Items}", new[] { "Tea", "Coffee" });
19+
Log.Information("Cart contains {@Items}", new[] { "Apricots" });
20+
Log.Information("Cart contains {@Items}", new[] { "Peanuts", "Chocolate" });
21+
22+
Log.CloseAndFlush();
23+
}
24+
}
25+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyConfiguration("")]
9+
[assembly: AssemblyCompany("")]
10+
[assembly: AssemblyProduct("Sample")]
11+
[assembly: AssemblyTrademark("")]
12+
13+
// Setting ComVisible to false makes the types in this assembly not visible
14+
// to COM components. If you need to access a type in this assembly from
15+
// COM, set the ComVisible attribute to true on that type.
16+
[assembly: ComVisible(false)]
17+
18+
// The following GUID is for the ID of the typelib if this project is exposed to COM
19+
[assembly: Guid("776eecac-3c50-45ea-847d-0ebe5158e51e")]

example/Sample/Sample.xproj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
8+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
9+
<PropertyGroup Label="Globals">
10+
<ProjectGuid>776eecac-3c50-45ea-847d-0ebe5158e51e</ProjectGuid>
11+
<RootNamespace>Sample</RootNamespace>
12+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
13+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
14+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
15+
</PropertyGroup>
16+
17+
<PropertyGroup>
18+
<SchemaVersion>2.0</SchemaVersion>
19+
</PropertyGroup>
20+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
21+
</Project>

example/Sample/project.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"version": "1.0.0-*",
3+
"buildOptions": {
4+
"emitEntryPoint": true
5+
},
6+
7+
"dependencies": {
8+
"Microsoft.NETCore.App": {
9+
"type": "platform",
10+
"version": "1.0.1"
11+
},
12+
"Serilog.Filters.Expressions": {"target": "project"},
13+
"Serilog": "2.3.0",
14+
"Serilog.Sinks.Literate": "2.0.0",
15+
"Superpower": "1.0.0"
16+
},
17+
18+
"frameworks": {
19+
"netcoreapp1.0": {
20+
"imports": "dnxcore50"
21+
}
22+
}
23+
}

global.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"projects": [ "src", "test", "example" ],
3+
"sdk": {
4+
"version": "1.0.0-preview2-003131"
5+
}
6+
}

0 commit comments

Comments
 (0)