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

2.12.0 Release #1705

Merged
merged 43 commits into from Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7521f17
Dev version bump [skip ci]
nblumhardt Apr 24, 2022
fabc2cb
update refs (#1674)
SimonCropp May 4, 2022
81e9dee
Remove redundant `.` from example message
nblumhardt Jun 29, 2022
45386bb
add explicit net6 target (#1703)
SimonCropp Jul 25, 2022
c4ec767
Remove wrong XDOC tag (#1699)
sungam3r Jul 25, 2022
ccd6e9c
More nullable annotation updates (#1700)
nblumhardt Jul 25, 2022
6eae5ac
Fix #1686 - nullable annotations for PropertyEnricher (#1704)
nblumhardt Jul 25, 2022
e01af65
Minor version bump - new target/features added
nblumhardt Jul 25, 2022
f986e62
Update NuGet publishing key
nblumhardt Jul 25, 2022
921037a
DateOnly and TimeOnly support (#1702)
SimonCropp Jul 26, 2022
f3349c1
remove BuildNativeUWP.ps1 from sln files (#1708)
SimonCropp Jul 27, 2022
255e76e
update Microsoft.NET.Test.Sdk and nullable (#1709)
SimonCropp Jul 27, 2022
5307e35
Bring Log.* methods exception nullability into line with ILogger (#1707)
nblumhardt Jul 27, 2022
9f0c43c
add missing VALUETUPLE check (#1711)
SimonCropp Jul 27, 2022
1123784
ScalarValue. value can be null (#1713)
SimonCropp Jul 28, 2022
1c926f0
out ScalarValue can be null (#1716)
SimonCropp Jul 29, 2022
f447af3
remove ! operator from nulls in conditions (#1719)
sungam3r Aug 1, 2022
7ec90ba
nullables in SettingValueConversions CallableConfigurationMethodFinde…
SimonCropp Aug 2, 2022
de4544d
format and formatProvider can be null (#1715)
SimonCropp Aug 2, 2022
70237f4
minor csproj cleanup (#1712)
SimonCropp Aug 2, 2022
382660a
Introduce file-scoped namespaces (#1725)
sungam3r Aug 9, 2022
b542985
update xunit (#1724)
SimonCropp Aug 9, 2022
15feab4
use some auto properties (#1723)
SimonCropp Aug 9, 2022
7c59f84
nullable in MessageTemplateParser (#1722)
SimonCropp Aug 9, 2022
1e16547
SettingValueConversions.ConvertToType() value cant be null (#1721)
SimonCropp Aug 17, 2022
635667b
Nullable annotations for destructuring policies (#1720)
SimonCropp Aug 17, 2022
fb964f8
rename ImmutableStack<ILogEventEnricher> to EnricherStack (#1728)
SimonCropp Aug 23, 2022
3214c47
Finish nullable. now enabled globally (#1729)
SimonCropp Aug 25, 2022
ec15a62
suppress CheckEolTargetFramework (#1730)
SimonCropp Aug 25, 2022
0ecc14b
use some lambda expressions (#1731)
SimonCropp Aug 25, 2022
9aff35a
use some compound assignments (#1732)
SimonCropp Aug 25, 2022
365adae
file scoped namespaces (#1734)
SimonCropp Aug 25, 2022
5a69b46
forgot to remove some Nullable>enable (#1735)
SimonCropp Aug 26, 2022
bed99cf
leverage ITuple interface (#1733)
SimonCropp Aug 30, 2022
c5a5b44
global usings (#1736)
SimonCropp Aug 31, 2022
70e729d
use some patterns (#1739)
SimonCropp Sep 1, 2022
e0c533d
minor cleanups (#1746)
SimonCropp Sep 5, 2022
1819ee7
refs (#1747)
SimonCropp Sep 5, 2022
3bd65ef
remove redundant LogEventLevel (#1745)
SimonCropp Sep 5, 2022
fd36c3e
remove redundant type names (#1741)
SimonCropp Sep 6, 2022
4d13be5
guard against null (#1742)
SimonCropp Sep 9, 2022
7740c90
Initial support for `IAsyncDisposable` sinks (#1750)
nblumhardt Sep 12, 2022
47df92d
Fix nullability of LogContext.PushProperty value arg (#1751)
nblumhardt Sep 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}
}