Skip to content

Commit

Permalink
Finish nullable. now enabled globally (serilog#1729)
Browse files Browse the repository at this point in the history
* nullable in LogEventProperty

* nullable in JsonValueFormatter

* nullable in EventProperty

* nullable in LogContext

* enable nullable for EnricherStack

* remove "#nullable enable" and enable globally

* Update Logger.cs
  • Loading branch information
SimonCropp authored and Twinki14 committed Dec 30, 2023
1 parent 37aa2c7 commit 39d66f5
Show file tree
Hide file tree
Showing 82 changed files with 31 additions and 101 deletions.
1 change: 1 addition & 0 deletions Directory.Build.props
Expand Up @@ -7,6 +7,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="all" />
Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Capturing/DepthLimiter.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;

using Serilog.Core;
Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Capturing/GetablePropertyFinder.cs
Expand Up @@ -12,7 +12,6 @@
// 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;
Expand Down
3 changes: 1 addition & 2 deletions src/Serilog/Capturing/MessageTemplateProcessor.cs
Expand Up @@ -12,7 +12,6 @@
// 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;
Expand All @@ -38,7 +37,7 @@ public void Process(string messageTemplate, object?[]? messageTemplateParameters
properties = _propertyBinder.ConstructProperties(parsedTemplate, messageTemplateParameters);
}

public LogEventProperty CreateProperty(string? name, object? value, bool destructureObjects = false)
public LogEventProperty CreateProperty(string name, object? value, bool destructureObjects = false)
{
return _propertyValueConverter.CreateProperty(name, value, destructureObjects);
}
Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Capturing/PropertyBinder.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using Serilog.Debugging;
using Serilog.Events;
Expand Down
3 changes: 1 addition & 2 deletions src/Serilog/Capturing/PropertyValueConverter.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -94,7 +93,7 @@ partial class PropertyValueConverter : ILogEventPropertyFactory, ILogEventProper
_depthLimiter = new(maximumDestructuringDepth, this);
}

public LogEventProperty CreateProperty(string? name, object? value, bool destructureObjects = false)
public LogEventProperty CreateProperty(string name, object? value, bool destructureObjects = false)
{
return new(name, CreatePropertyValue(value, destructureObjects));
}
Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Configuration/LoggerAuditSinkConfiguration.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using Serilog.Core;
using Serilog.Events;
Expand Down
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using System.Collections;
using Serilog.Core;
Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Configuration/LoggerEnrichmentConfiguration.cs
Expand Up @@ -12,7 +12,6 @@
// 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;
Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Configuration/LoggerFilterConfiguration.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using Serilog.Core;
using Serilog.Core.Filters;
Expand Down
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using Serilog.Core;
using Serilog.Events;
Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Configuration/LoggerSettingsConfiguration.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using System.Collections.Generic;
using Serilog.Settings.KeyValuePairs;
Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Configuration/LoggerSinkConfiguration.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand Down
18 changes: 9 additions & 9 deletions src/Serilog/Context/EnricherStack.cs
Expand Up @@ -25,8 +25,8 @@ namespace Serilog.Context
{
class EnricherStack: IEnumerable<ILogEventEnricher>
{
readonly EnricherStack _under;
readonly ILogEventEnricher _top;
readonly EnricherStack? _under;
readonly ILogEventEnricher? _top;

EnricherStack()
{
Expand All @@ -53,39 +53,39 @@ class EnricherStack: IEnumerable<ILogEventEnricher>

public EnricherStack Push(ILogEventEnricher t) => new(this, t);

public ILogEventEnricher Top => _top;
public ILogEventEnricher Top => _top!;

internal struct Enumerator : IEnumerator<ILogEventEnricher>
{
readonly EnricherStack _stack;
EnricherStack _top;
ILogEventEnricher _current;
ILogEventEnricher? _current;

public Enumerator(EnricherStack stack)
{
_stack = stack;
_top = stack;
_current = default;
_current = null;
}

public bool MoveNext()
{
if (_top.IsEmpty)
return false;
_current = _top.Top;
_top = _top._under;
_top = _top._under!;
return true;
}

public void Reset()
{
_top = _stack;
_current = default;
_current = null;
}

public ILogEventEnricher Current => _current;
public ILogEventEnricher Current => _current!;

object IEnumerator.Current => _current;
object IEnumerator.Current => _current!;

public void Dispose()
{
Expand Down
17 changes: 10 additions & 7 deletions src/Serilog/Context/LogContext.cs
Expand Up @@ -52,12 +52,12 @@ namespace Serilog.Context
public static class LogContext
{
#if ASYNCLOCAL
static readonly AsyncLocal<EnricherStack> Data = new();
static readonly AsyncLocal<EnricherStack?> Data = new();
#elif REMOTING
static readonly string DataSlotName = typeof(LogContext).FullName + "@" + Guid.NewGuid();
#else // DOTNET_51
[ThreadStatic]
static EnricherStack Data;
static EnricherStack? Data;
#endif

/// <summary>
Expand Down Expand Up @@ -215,15 +215,15 @@ public void Dispose()

#if ASYNCLOCAL

static EnricherStack Enrichers
static EnricherStack? Enrichers
{
get => Data.Value;
set => Data.Value = value;
}

#elif REMOTING

static EnricherStack Enrichers
static EnricherStack? Enrichers
{
get
{
Expand All @@ -238,7 +238,10 @@ static EnricherStack Enrichers
oldHandle.Dispose();
}

CallContext.LogicalSetData(DataSlotName, new DisposableObjectHandle(value));
if (value != null)
{
CallContext.LogicalSetData(DataSlotName, new DisposableObjectHandle(value));
}
}
}

Expand All @@ -251,7 +254,7 @@ public DisposableObjectHandle(object o)
{
}

public override object InitializeLifetimeService()
public override object? InitializeLifetimeService()
{
var lease = base.InitializeLifetimeService() as ILease;
lease?.Register(LifeTimeSponsor);
Expand All @@ -269,7 +272,7 @@ public void Dispose()

#else // DOTNET_51

static EnricherStack Enrichers
static EnricherStack? Enrichers
{
get => Data;
set => Data = value;
Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Context/LogContextEnricher.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using Serilog.Core;
using Serilog.Events;

Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Core/Enrichers/ConditionalEnricher.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using Serilog.Events;

Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Core/Enrichers/EmptyEnricher.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using Serilog.Events;

namespace Serilog.Core.Enrichers
Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Core/Enrichers/FixedPropertyEnricher.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using Serilog.Events;

Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Core/Enrichers/PropertyEnricher.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using Serilog.Events;

Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Core/Enrichers/SafeAggregateEnricher.cs
Expand Up @@ -12,7 +12,6 @@
// 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;
Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Core/Filters/DelegateFilter.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using Serilog.Events;

Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Core/IDestructuringPolicy.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System.Diagnostics.CodeAnalysis;
using Serilog.Events;

Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Core/ILogEventPropertyFactory.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable

using Serilog.Events;

Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Core/LevelOverrideMap.cs
Expand Up @@ -12,7 +12,6 @@
// 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;
Expand Down
2 changes: 1 addition & 1 deletion src/Serilog/Core/Logger.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -1332,6 +1331,7 @@ public void Fatal(Exception? exception, string messageTemplate, params object?[]
[NotNullWhen(true)] out MessageTemplate? parsedTemplate,
[NotNullWhen(true)] out IEnumerable<LogEventProperty>? boundProperties)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
if (messageTemplate == null)
{
parsedTemplate = null;
Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Core/LoggingLevelSwitch.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using Serilog.Events;

namespace Serilog.Core
Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Core/Pipeline/MessageTemplateCache.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using Serilog.Events;

Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Core/Pipeline/SilentLogger.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Core/Sinks/AggregateSink.cs
Expand Up @@ -12,7 +12,6 @@
// 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;
Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Core/Sinks/ConditionalSink.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using Serilog.Events;

Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Core/Sinks/DisposeDelegatingSink.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using Serilog.Events;
using System;

Expand Down
1 change: 0 additions & 1 deletion src/Serilog/Core/Sinks/DisposingSafeAggregateSink.cs
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using Serilog.Debugging;
using System;
using System.Collections.Generic;
Expand Down

0 comments on commit 39d66f5

Please sign in to comment.