Skip to content

Commit

Permalink
Merge pull request #1705 from serilog/dev
Browse files Browse the repository at this point in the history
2.12.0 Release
  • Loading branch information
nblumhardt committed Sep 13, 2022
2 parents e5883c5 + 47df92d commit 9f86301
Show file tree
Hide file tree
Showing 217 changed files with 17,086 additions and 17,876 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Expand Up @@ -16,3 +16,6 @@ end_of_line = lf

[*.{cmd, bat}]
end_of_line = crlf

# C# formatting settings - Namespace options
csharp_style_namespace_declarations = file_scoped:suggestion
19 changes: 0 additions & 19 deletions BuildNativeUWP.ps1

This file was deleted.

7 changes: 7 additions & 0 deletions Directory.Build.props
Expand Up @@ -3,6 +3,13 @@
<Target Name="GetPackagingOutputs" />
<PropertyGroup>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="all" />
Expand Down
7 changes: 7 additions & 0 deletions Directory.Build.targets
@@ -0,0 +1,7 @@
<Project>

<ItemGroup>
<Using Remove="System.Net.Http" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -21,7 +21,7 @@ Unlike other logging libraries, Serilog is built from the ground up to record _s
var position = new { Latitude = 25, Longitude = 134 };
var elapsedMs = 34;

log.Information("Processed {@Position} in {Elapsed} ms.", position, elapsedMs);
log.Information("Processed {@Position} in {Elapsed} ms", position, elapsedMs);
```

Serilog uses [message templates](https://messagetemplates.org), a simple DSL that extends .NET format strings with _named_ as well as positional parameters. Instead of formatting events immediately into text, Serilog captures the values associated with each named parameter.
Expand Down Expand Up @@ -61,9 +61,9 @@ Supporting structured data doesn't mean giving up text: when Serilog writes even
Serilog is installed from NuGet. To view log events, one or more sinks need to be installed as well, here we'll use the pretty-printing console sink, and a rolling file set:

```
Install-Package Serilog
Install-Package Serilog.Sinks.Console
Install-Package Serilog.Sinks.File
dotnet add package Serilog
dotnet add package Serilog.Sinks.Console
dotnet add package Serilog.Sinks.File
```

The simplest way to set up Serilog is using the static `Log` class. A `LoggerConfiguration` is used to create and assign the default logger.
Expand Down
1 change: 0 additions & 1 deletion Serilog.sln
Expand Up @@ -8,7 +8,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{E9D1B5
appveyor.yml = appveyor.yml
Build.ps1 = Build.ps1
build.sh = build.sh
BuildNativeUWP.ps1 = BuildNativeUWP.ps1
CHANGES.md = CHANGES.md
Directory.Build.props = Directory.Build.props
global.json = global.json
Expand Down
1 change: 1 addition & 0 deletions Serilog.sln.DotSettings
Expand Up @@ -195,6 +195,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/VBNaming/PredefinedNamingRules/=StaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/VBNaming/PredefinedNamingRules/=TypeParameters/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/VBNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EdotCover_002EIde_002ECore_002EFilterManagement_002EModel_002ESolutionFilterSettingsManagerMigrateSettings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpFileLayoutPatternsUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
Expand Down
5 changes: 2 additions & 3 deletions appveyor.yml
@@ -1,13 +1,12 @@
version: '{build}'
skip_tags: true
image:
- Visual Studio 2019
- Visual Studio 2022
- Ubuntu
configuration: Release
test: off
build_script:
- ps: ./Build.ps1
- ps: ./BuildNativeUWP.ps1
for:
-
matrix:
Expand All @@ -21,7 +20,7 @@ artifacts:
deploy:
- provider: NuGet
api_key:
secure: Koq5UhgDHkK7NgoFMwKE+NH8l3E/YmRSgnokN9lTGJ38gJ62VWyiXauHi7KLQ3sH
secure: 45/vGyNCdoOvWSorcVX6qYM3oC/mCBj0CDRXNZP4twlIrBiZ9sKtKMdHwufm4ogS
on:
branch: /^(main|dev)$/
- provider: GitHub
Expand Down
2 changes: 1 addition & 1 deletion global.json
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "5.0.202",
"version": "6.0.300",
"allowPrerelease": false,
"rollForward": "latestFeature"
}
Expand Down
87 changes: 39 additions & 48 deletions src/Serilog/Capturing/DepthLimiter.cs
Expand Up @@ -12,71 +12,62 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
namespace Serilog.Capturing;

using Serilog.Core;
using Serilog.Debugging;
using Serilog.Events;
using Serilog.Parsing;

namespace Serilog.Capturing
partial class PropertyValueConverter
{
partial class PropertyValueConverter
class DepthLimiter : ILogEventPropertyValueFactory
{
class DepthLimiter : ILogEventPropertyValueFactory
{
[ThreadStatic]
static int _currentDepth;
[ThreadStatic]
static int _currentDepth;

readonly int _maximumDestructuringDepth;
readonly PropertyValueConverter _propertyValueConverter;
readonly int _maximumDestructuringDepth;
readonly PropertyValueConverter _propertyValueConverter;

public DepthLimiter(int maximumDepth, PropertyValueConverter propertyValueConverter)
{
_maximumDestructuringDepth = maximumDepth;
_propertyValueConverter = propertyValueConverter;
}
public DepthLimiter(int maximumDepth, PropertyValueConverter propertyValueConverter)
{
_maximumDestructuringDepth = maximumDepth;
_propertyValueConverter = propertyValueConverter;
}

public static void SetCurrentDepth(int depth)
{
_currentDepth = depth;
}
public static void SetCurrentDepth(int depth)
{
_currentDepth = depth;
}

public LogEventPropertyValue CreatePropertyValue(object? value, Destructuring destructuring)
{
var storedDepth = _currentDepth;
public LogEventPropertyValue CreatePropertyValue(object? value, Destructuring destructuring)
{
var storedDepth = _currentDepth;

var result = DefaultIfMaximumDepth(storedDepth) ??
_propertyValueConverter.CreatePropertyValue(value, destructuring, storedDepth + 1);
var result = DefaultIfMaximumDepth(storedDepth) ??
_propertyValueConverter.CreatePropertyValue(value, destructuring, storedDepth + 1);

_currentDepth = storedDepth;
_currentDepth = storedDepth;

return result;
}
return result;
}

LogEventPropertyValue ILogEventPropertyValueFactory.CreatePropertyValue(object value, bool destructureObjects)
{
var storedDepth = _currentDepth;
LogEventPropertyValue ILogEventPropertyValueFactory.CreatePropertyValue(object value, bool destructureObjects)
{
var storedDepth = _currentDepth;

var result = DefaultIfMaximumDepth(storedDepth) ??
_propertyValueConverter.CreatePropertyValue(value, destructureObjects, storedDepth + 1);
var result = DefaultIfMaximumDepth(storedDepth) ??
_propertyValueConverter.CreatePropertyValue(value, destructureObjects, storedDepth + 1);

_currentDepth = storedDepth;
_currentDepth = storedDepth;

return result;
}
return result;
}

LogEventPropertyValue? DefaultIfMaximumDepth(int depth)
LogEventPropertyValue? DefaultIfMaximumDepth(int depth)
{
if (depth == _maximumDestructuringDepth)
{
if (depth == _maximumDestructuringDepth)
{
SelfLog.WriteLine("Maximum destructuring depth reached.");
return new ScalarValue(null);
}

return null;
SelfLog.WriteLine("Maximum destructuring depth reached.");
return new ScalarValue(null);
}

return null;
}
}
}
49 changes: 21 additions & 28 deletions src/Serilog/Capturing/GetablePropertyFinder.cs
Expand Up @@ -12,42 +12,35 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Serilog.Capturing;

namespace Serilog.Capturing
static class GetablePropertyFinder
{
static class GetablePropertyFinder
internal static IEnumerable<PropertyInfo> GetPropertiesRecursive(this Type type)
{
internal static IEnumerable<PropertyInfo> GetPropertiesRecursive(this Type type)
{
var seenNames = new HashSet<string>();

var currentTypeInfo = type.GetTypeInfo();
var seenNames = new HashSet<string>();

while (currentTypeInfo.AsType() != typeof(object))
{
var unseenProperties = currentTypeInfo.DeclaredProperties.Where(p => p.CanRead &&
p.GetMethod!.IsPublic && !p.GetMethod.IsStatic &&
(p.Name != "Item" || p.GetIndexParameters().Length == 0) && !seenNames.Contains(p.Name));
var currentTypeInfo = type.GetTypeInfo();

foreach (var propertyInfo in unseenProperties)
{
seenNames.Add(propertyInfo.Name);
yield return propertyInfo;
}
while (currentTypeInfo.AsType() != typeof(object))
{
var unseenProperties = currentTypeInfo.DeclaredProperties.Where(p => p.CanRead &&
p.GetMethod!.IsPublic && !p.GetMethod.IsStatic &&
(p.Name != "Item" || p.GetIndexParameters().Length == 0) && !seenNames.Contains(p.Name));

var baseType = currentTypeInfo.BaseType;
if (baseType == null)
{
yield break;
}
foreach (var propertyInfo in unseenProperties)
{
seenNames.Add(propertyInfo.Name);
yield return propertyInfo;
}

currentTypeInfo = baseType.GetTypeInfo();
var baseType = currentTypeInfo.BaseType;
if (baseType == null)
{
yield break;
}

currentTypeInfo = baseType.GetTypeInfo();
}
}
}
51 changes: 22 additions & 29 deletions src/Serilog/Capturing/MessageTemplateProcessor.cs
Expand Up @@ -12,40 +12,33 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using Serilog.Core;
using Serilog.Core.Pipeline;
using Serilog.Events;
using Serilog.Parsing;
namespace Serilog.Capturing;

namespace Serilog.Capturing
class MessageTemplateProcessor : ILogEventPropertyFactory
{
class MessageTemplateProcessor : ILogEventPropertyFactory
{
readonly MessageTemplateCache _parser = new(new MessageTemplateParser());
readonly PropertyBinder _propertyBinder;
readonly PropertyValueConverter _propertyValueConverter;
readonly MessageTemplateCache _parser = new(new MessageTemplateParser());
readonly PropertyBinder _propertyBinder;
readonly PropertyValueConverter _propertyValueConverter;

public MessageTemplateProcessor(PropertyValueConverter propertyValueConverter)
{
_propertyValueConverter = propertyValueConverter;
_propertyBinder = new(_propertyValueConverter);
}
public MessageTemplateProcessor(PropertyValueConverter propertyValueConverter)
{
_propertyValueConverter = propertyValueConverter;
_propertyBinder = new(_propertyValueConverter);
}

public void Process(string messageTemplate, object?[]? messageTemplateParameters, out MessageTemplate parsedTemplate, out EventProperty[] properties)
{
parsedTemplate = _parser.Parse(messageTemplate);
properties = _propertyBinder.ConstructProperties(parsedTemplate, messageTemplateParameters);
}
public void Process(string messageTemplate, object?[]? messageTemplateParameters, out MessageTemplate parsedTemplate, out EventProperty[] properties)
{
parsedTemplate = _parser.Parse(messageTemplate);
properties = _propertyBinder.ConstructProperties(parsedTemplate, messageTemplateParameters);
}

public LogEventProperty CreateProperty(string? name, object? value, bool destructureObjects = false)
{
return _propertyValueConverter.CreateProperty(name, value, destructureObjects);
}
public LogEventProperty CreateProperty(string name, object? value, bool destructureObjects = false)
{
return _propertyValueConverter.CreateProperty(name, value, destructureObjects);
}

public LogEventPropertyValue CreatePropertyValue(object? value, bool destructureObjects = false)
{
return _propertyValueConverter.CreatePropertyValue(value, destructureObjects);
}
public LogEventPropertyValue CreatePropertyValue(object? value, bool destructureObjects = false)
{
return _propertyValueConverter.CreatePropertyValue(value, destructureObjects);
}
}

0 comments on commit 9f86301

Please sign in to comment.