Skip to content

clean up some whitespace #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $commitHash = $(git rev-parse --short HEAD)
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]

echo "build: Package version suffix is $suffix"
echo "build: Build version suffix is $buildSuffix"
echo "build: Build version suffix is $buildSuffix"

foreach ($src in ls src/*) {
Push-Location $src
Expand All @@ -30,7 +30,7 @@ foreach ($src in ls src/*) {
} else {
& dotnet pack -c Release --include-source --no-build -o ..\..\artifacts
}
if($LASTEXITCODE -ne 0) { exit 1 }
if($LASTEXITCODE -ne 0) { exit 1 }

Pop-Location
}
Expand Down
35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _Serilog Expressions_ [![Build status](https://ci.appveyor.com/api/projects/status/vmcskdk2wjn1rpps/branch/dev?svg=true)](https://ci.appveyor.com/project/serilog/serilog-expressions/branch/dev) [![NuGet Package](https://img.shields.io/nuget/vpre/serilog.expressions)](https://nuget.org/packages/serilog.expressions)

An embeddable mini-language for filtering, enriching, and formatting Serilog
An embeddable mini-language for filtering, enriching, and formatting Serilog
events, ideal for use with JSON or XML configuration.

## Getting started
Expand All @@ -11,14 +11,14 @@ Install the package from NuGet:
dotnet add package Serilog.Expressions
```

The package adds extension methods to Serilog's `Filter`, `WriteTo`, and
The package adds extension methods to Serilog's `Filter`, `WriteTo`, and
`Enrich` configuration objects, along with an `ExpressionTemplate`
type that's compatible with Serilog sinks accepting an
`ITextFormatter`.

### Filtering example

_Serilog.Expressions_ adds `ByExcluding()` and `ByIncludingOnly()`
_Serilog.Expressions_ adds `ByExcluding()` and `ByIncludingOnly()`
overloads to the `Filter` configuration object that accept filter
expressions:

Expand All @@ -38,8 +38,7 @@ in the package. To check expression syntax without throwing, see the

#### An `appSettings.json` JSON configuration example

In [`appSettings.json`
configuration](https://github.com/serilog/serilog-settings-configuration)
In [`appSettings.json` configuration](https://github.com/serilog/serilog-settings-configuration)
this is written as:

```json
Expand Down Expand Up @@ -68,7 +67,7 @@ this is written as:
<add key="serilog:using:Expressions" value="Serilog.Expressions" />
<add key="serilog:filter:ByExcluding.expression" value="RequestPath like '/health%'" />
</appSettings>
```
```

## Supported configuration APIs

Expand All @@ -91,14 +90,14 @@ Log.Logger = new LoggerConfiguration()
.WriteTo.Console(new ExpressionTemplate(
"[{@t:HH:mm:ss} {@l:u3} ({SourceContext})] {@m} (first item is {Cart[0]})\n{@x}"))
.CreateLogger();

// Produces log events like:
// [21:21:40 INF (Sample.Program)] Cart contains ["Tea","Coffee"] (first item is Tea)
```

Templates are based on .NET format strings, and support standard padding, alignment, and format specifiers.

Along with standard properties for the event timestamp (`@t`), level (`@l`) and so on, "holes" in expression templates can include complex
Along with standard properties for the event timestamp (`@t`), level (`@l`) and so on, "holes" in expression templates can include complex
expressions over the first-class properties of the event, like `{SourceContex}` and `{Cart[0]}` in the example..

Templates support customizable color themes when used with the `Console` sink:
Expand Down Expand Up @@ -165,7 +164,7 @@ A typical set of operators is supported:
* Indexers `a['b']` and `a[0]`
* Wildcard indexing - `a[?]` any, and `a[*]` all
* Conditional `if a then b else c` (all branches required; see also the section below on _conditional blocks_)

Comparision operators that act on text all accept an optional postfix `ci` modifier to select case-insensitive comparisons:

```
Expand All @@ -176,7 +175,7 @@ User.Name like 'n%' ci

Functions are called using typical `Identifier(args)` syntax.

Except for the `IsDefined()` function, the result of
Except for the `IsDefined()` function, the result of
calling a function will be undefined if:

* any argument is undefined, or
Expand Down Expand Up @@ -223,10 +222,10 @@ Log.Logger = new LoggerConfiguration()
.WriteTo.Console(new ExpressionTemplate(
"[{@t:HH:mm:ss} {@l:u3}{#if SourceContext is not null} ({SourceContext}){#end}] {@m}\n{@x}"))
.CreateLogger();

// Produces log events like:
// [21:21:45 INF] Starting up
// [21:21:46 INF (Sample.Program)] Firing engines
// [21:21:46 INF (Sample.Program)] Firing engines
```

The block between the `{#if <expr>}` and `{#end}` directives will only appear in the output if `<expr>` is `true` - in the example, events with a `SourceContext` include this in parentheses, while those without, don't.
Expand Down Expand Up @@ -302,7 +301,7 @@ ElementAt(@p, 'someName') ci
{ {Timestamp: @t, Username: User.Name} }\n
```

This output template shows the use of a space between the opening `{` of a hole, and the enclosed object literal with `Timestamp` and
This output template shows the use of a space between the opening `{` of a hole, and the enclosed object literal with `Timestamp` and
`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
it's not part of the output template syntax).

Expand Down Expand Up @@ -336,8 +335,8 @@ else
Compiled expression delegates return `LogEventPropertyValue` because this is the most
convenient type to work with in many Serilog scenarios (enrichers, sinks, ...). To
convert the result to plain-old-.NET-types like `string`, `bool`, `Dictionary<K,V>` and
`Array`, use the functions in the `Serilog.Expressions.ExpressionResult` class:
`Array`, use the functions in the `Serilog.Expressions.ExpressionResult` class:

```csharp
var result = compiled(someEvent);

Expand All @@ -356,12 +355,12 @@ User-defined functions can be plugged in by implementing static methods that:
* Have arguments of type `LogEventPropertyValue?` or `LogEvent`,
* If the `ci` modifier is supported, accept a `StringComparison`, and
* If culture-specific formatting or comparisons are used, accepts an `IFormatProvider`.

For example:

```csharp
public static class MyFunctions
{
{
public static LogEventPropertyValue? IsHello(
StringComparison comparison,
LogEventPropertyValue? maybeHello)
Expand All @@ -388,5 +387,5 @@ var expr = SerilogExpression.Compile("IsHello(User.Name)", new[] { myFunctions }

## Acknowledgements

Includes the parser combinator implementation from [Superpower](https://github.com/datalust/superpower), copyright Datalust,
Includes the parser combinator implementation from [Superpower](https://github.com/datalust/superpower), copyright Datalust,
Superpower Contributors, and Sprache Contributors; licensed under the Apache License, 2.0.
22 changes: 11 additions & 11 deletions example/Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ static void TextFormattingExample1()
.CreateLogger();

log.Information("Running {Example}", nameof(TextFormattingExample1));

log.ForContext<Program>()
.Information("Cart contains {@Items}", new[] { "Tea", "Coffee" });

log.ForContext<Program>()
.Information("Cart contains {@Items}", new[] { "Apricots" });
}
Expand All @@ -49,10 +49,10 @@ static void JsonFormattingExample()
.CreateLogger();

log.Information("Running {Example}", nameof(JsonFormattingExample));

log.ForContext<Program>()
.Information("Cart contains {@Items}", new[] { "Tea", "Coffee" });

log.ForContext<Program>()
.Warning("Cart is empty");
}
Expand All @@ -67,20 +67,20 @@ static void PipelineComponentExample()
.WriteTo.Console(outputTemplate:
"[{Timestamp:HH:mm:ss} {Level:u3} ({SourceContext})] {Message:lj} (first item is {FirstItem}){NewLine}{Exception}")
.CreateLogger();

log.Information("Running {Example}", nameof(PipelineComponentExample));

log.ForContext<Program>()
.Information("Cart contains {@Items}", new[] { "Tea", "Coffee" });

log.ForContext<Program>()
.Information("Cart contains {@Items}", new[] { "Apricots" });
}

static void TextFormattingExample2()
{
// Emulates `Microsoft.Extensions.Logging`'s `ConsoleLogger`.

var melon = new TemplateTheme(TemplateTheme.Literate, new Dictionary<TemplateThemeStyle, string>
{
// `Information` is dark green in MEL.
Expand All @@ -102,11 +102,11 @@ static void TextFormattingExample2()

var program = log.ForContext<Program>();
program.Information("Host listening at {ListenUri}", "https://hello-world.local");

program
.ForContext("Scope", new[] {"Main", "TextFormattingExample2()"})
.Information("HTTP {Method} {Path} responded {StatusCode} in {Elapsed:0.000} ms", "GET", "/api/hello", 200, 1.23);

program.Warning("We've reached the end of the line");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Serilog.Expressions/Expressions/Ast/CallExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public CallExpression(bool ignoreCase, string operatorName, params Expression[]
}

public bool IgnoreCase { get; }

public string OperatorName { get; }

public Expression[] Operands { get; }
Expand Down
4 changes: 2 additions & 2 deletions src/Serilog.Expressions/Expressions/Ast/ConstantExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
using Serilog.Events;

namespace Serilog.Expressions.Ast
{
{
class ConstantExpression : Expression
{
public ConstantExpression(LogEventPropertyValue constant)
Expand All @@ -26,7 +26,7 @@ public ConstantExpression(LogEventPropertyValue constant)
}

public LogEventPropertyValue Constant { get; }

public override string ToString()
{
if (Constant is ScalarValue sv)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ObjectExpression(Member[] members)
{
Members = members;
}

public Member[] Members { get; }

public override string ToString()
Expand Down
2 changes: 1 addition & 1 deletion src/Serilog.Expressions/Expressions/Ast/PropertyMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public PropertyMember(string name, Expression value)
Name = name;
Value = value;
}

public override string ToString()
{
return $"{new ScalarValue(Name)}: {Value}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Serilog.Expressions.Compilation.Arrays
class ConstantArrayEvaluator : IdentityTransformer
{
static readonly ConstantArrayEvaluator Instance = new ConstantArrayEvaluator();

public static Expression Evaluate(Expression expression)
{
return Instance.Transform(expression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static Expression Translate(Expression expression)
actual = WildcardComprehensionTransformer.Expand(actual);
return actual;
}

public static Evaluatable Compile(Expression expression, IFormatProvider? formatProvider,
NameResolver nameResolver)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ExpressionConstantMapper(IDictionary<object, Expression> mapping)

protected override Expression VisitConstant(ConstantExpression node)
{
if (node.Value != null &&
if (node.Value != null &&
node.Value is ScalarValue sv &&
_mapping.TryGetValue(sv.Value, out var substitute))
return substitute;
Expand Down
Loading