Skip to content
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

A few minor cleanups #48

Merged
merged 5 commits into from
Jun 20, 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
19 changes: 9 additions & 10 deletions src/Serilog.Expressions/Expressions/Compilation/Linq/Intrinsics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using System.Text.RegularExpressions;
using Serilog.Events;
using Serilog.Expressions.Runtime;
using Serilog.Formatting.Display;
using Serilog.Parsing;
using Serilog.Templates.Compilation;

Expand All @@ -32,7 +31,7 @@ static class Intrinsics
{
static readonly LogEventPropertyValue NegativeOne = new ScalarValue(-1);
static readonly LogEventPropertyValue Tombstone = new ScalarValue("😬 (if you see this you have found a bug.)");

public static List<LogEventPropertyValue?> CollectSequenceElements(LogEventPropertyValue?[] elements)
{
return elements.ToList();
Expand All @@ -53,18 +52,18 @@ static class Intrinsics
if (content is SequenceValue sequence)
foreach (var element in sequence.Elements)
elements.Add(element);

return elements;
}

public static LogEventPropertyValue ConstructSequenceValue(List<LogEventPropertyValue?> elements)
{
if (elements.Any(el => el == null))
return new SequenceValue(elements.Where(el => el != null));

return new SequenceValue(elements);
}

public static List<LogEventProperty> CollectStructureProperties(string[] names, LogEventPropertyValue?[] values)
{
var properties = new List<LogEventProperty>();
Expand All @@ -85,7 +84,7 @@ public static LogEventPropertyValue ConstructStructureValue(List<LogEventPropert

return new StructureValue(properties);
}

public static List<LogEventProperty> ExtendStructureValueWithSpread(
List<LogEventProperty> properties,
LogEventPropertyValue? content)
Expand All @@ -99,7 +98,7 @@ public static List<LogEventProperty> ExtendStructureValueWithSpread(

return properties;
}

public static List<LogEventProperty> ExtendStructureValueWithProperty(
List<LogEventProperty> properties,
string name,
Expand Down Expand Up @@ -129,7 +128,7 @@ public static bool CoerceToScalarBoolean(LogEventPropertyValue value)
return b;
return false;
}

public static LogEventPropertyValue? IndexOfMatch(LogEventPropertyValue value, Regex regex)
{
if (value is ScalarValue scalar &&
Expand Down Expand Up @@ -193,9 +192,9 @@ public static string RenderMessage(CompiledMessageToken formatter, EvaluationCon
if (token is PropertyToken {Format: { }} pt)
{
elements ??= new List<LogEventPropertyValue>();

var space = new StringWriter();

pt.Render(logEvent.Properties, space, formatProvider);
elements.Add(new ScalarValue(space.ToString()));
}
Expand Down
11 changes: 5 additions & 6 deletions src/Serilog.Expressions/Templates/ExpressionTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using System.IO;
using Serilog.Events;
using Serilog.Expressions;
using Serilog.Expressions.Compilation;
using Serilog.Formatting;
using Serilog.Templates.Compilation;
using Serilog.Templates.Compilation.NameResolution;
Expand All @@ -32,7 +31,7 @@ namespace Serilog.Templates
public class ExpressionTemplate : ITextFormatter
{
readonly CompiledTemplate _compiled;

/// <summary>
/// Construct an <see cref="ExpressionTemplate"/>.
/// </summary>
Expand Down Expand Up @@ -89,10 +88,10 @@ public static bool TryParse(
formatProvider,
TemplateFunctionNameResolver.Build(nameResolver, planned),
SelectTheme(theme, applyThemeWhenOutputIsRedirected)));

return true;
}

ExpressionTemplate(CompiledTemplate compiled)
{
_compiled = compiled;
Expand Down Expand Up @@ -121,9 +120,9 @@ public ExpressionTemplate(
var templateParser = new TemplateParser();
if (!templateParser.TryParse(template, out var parsed, out var error))
throw new ArgumentException(error);

var planned = TemplateLocalNameBinder.BindLocalValueNames(parsed);

_compiled = TemplateCompiler.Compile(
planned,
formatProvider,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
</PropertyGroup>

Expand Down
12 changes: 0 additions & 12 deletions test/Serilog.Expressions.PerformanceTests/Support/NullSink.cs

This file was deleted.

2 changes: 0 additions & 2 deletions test/Serilog.Expressions.Tests/ExpressionEvaluationTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using Serilog.Events;
using Serilog.Expressions.Runtime;
using Serilog.Expressions.Tests.Support;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using Serilog.Expressions.Tests.Support;
using Xunit;

#nullable enable

namespace Serilog.Expressions.Tests.Expressions
{
public class NameResolverTests
Expand All @@ -15,15 +13,15 @@ public class NameResolverTests
{
if (!Coerce.Numeric(number, out var num))
return null;

return new ScalarValue(num + 42);
}

public static LogEventPropertyValue? SecretWordAt(string word, LogEventPropertyValue? index)
{
if (!Coerce.Numeric(index, out var i))
return null;

return new ScalarValue(word[(int)i].ToString());
}

Expand Down Expand Up @@ -62,7 +60,7 @@ public void UserDefinedFunctionsAreCallableInExpressions()
nameResolver: new StaticMemberNameResolver(typeof(NameResolverTests)));
Assert.True(Coerce.IsTrue(expr(Some.InformationEvent())));
}

[Fact]
public void UserDefinedFunctionsCanReceiveUserProvidedParameters()
{
Expand Down