From c394579677f08889229751d19c8a5a1fe3ce63c9 Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Sun, 15 Oct 2023 14:30:55 +0100 Subject: [PATCH] Enable nullability annotations in the project --- .../Enrichers/CachedPropertyEnricher.cs | 5 ++--- .../Enrichers/EnvironmentVariableEnricher.cs | 2 +- .../EnvironmentLoggerConfigurationExtensions.cs | 2 +- .../Serilog.Enrichers.Environment.csproj | 2 ++ 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Serilog.Enrichers.Environment/Enrichers/CachedPropertyEnricher.cs b/src/Serilog.Enrichers.Environment/Enrichers/CachedPropertyEnricher.cs index a8097e4..9bc92d5 100644 --- a/src/Serilog.Enrichers.Environment/Enrichers/CachedPropertyEnricher.cs +++ b/src/Serilog.Enrichers.Environment/Enrichers/CachedPropertyEnricher.cs @@ -19,7 +19,7 @@ namespace Serilog.Enrichers { public abstract class CachedPropertyEnricher: ILogEventEnricher { - private LogEventProperty _cachedProperty { get; set; } + private LogEventProperty? _cachedProperty { get; set; } /// /// Enrich the log event. @@ -35,8 +35,7 @@ private LogEventProperty GetLogEventProperty(ILogEventPropertyFactory propertyFa { // Don't care about thread-safety, in the worst case the field gets overwritten and one // property will be GCed - if (_cachedProperty == null) - _cachedProperty = CreateProperty(propertyFactory); + _cachedProperty ??= CreateProperty(propertyFactory); return _cachedProperty; } diff --git a/src/Serilog.Enrichers.Environment/Enrichers/EnvironmentVariableEnricher.cs b/src/Serilog.Enrichers.Environment/Enrichers/EnvironmentVariableEnricher.cs index a51afec..092655c 100644 --- a/src/Serilog.Enrichers.Environment/Enrichers/EnvironmentVariableEnricher.cs +++ b/src/Serilog.Enrichers.Environment/Enrichers/EnvironmentVariableEnricher.cs @@ -31,7 +31,7 @@ public class EnvironmentVariableEnricher : CachedPropertyEnricher /// public string EnvironmentVariablePropertyName { get; } - public EnvironmentVariableEnricher(string envVarName, string propertyName) + public EnvironmentVariableEnricher(string envVarName, string? propertyName) { _envVarName = envVarName; EnvironmentVariablePropertyName = propertyName ?? envVarName; diff --git a/src/Serilog.Enrichers.Environment/EnvironmentLoggerConfigurationExtensions.cs b/src/Serilog.Enrichers.Environment/EnvironmentLoggerConfigurationExtensions.cs index 7e8d195..55a8e66 100644 --- a/src/Serilog.Enrichers.Environment/EnvironmentLoggerConfigurationExtensions.cs +++ b/src/Serilog.Enrichers.Environment/EnvironmentLoggerConfigurationExtensions.cs @@ -69,7 +69,7 @@ public static LoggerConfiguration WithEnvironmentUserName( /// The Optional name of the property. If empty is used /// Configuration object allowing method chaining. public static LoggerConfiguration WithEnvironmentVariable( - this LoggerEnrichmentConfiguration enrichmentConfiguration, string environmentVariableName, string propertyName = null) + this LoggerEnrichmentConfiguration enrichmentConfiguration, string environmentVariableName, string? propertyName = null) { if (enrichmentConfiguration == null) throw new ArgumentNullException(nameof(enrichmentConfiguration)); var environmentVariableEnricher = new EnvironmentVariableEnricher(environmentVariableName, propertyName); diff --git a/src/Serilog.Enrichers.Environment/Serilog.Enrichers.Environment.csproj b/src/Serilog.Enrichers.Environment/Serilog.Enrichers.Environment.csproj index cb2fdb9..31d3ed8 100644 --- a/src/Serilog.Enrichers.Environment/Serilog.Enrichers.Environment.csproj +++ b/src/Serilog.Enrichers.Environment/Serilog.Enrichers.Environment.csproj @@ -17,6 +17,8 @@ https://github.com/serilog/serilog-enrichers-environment git false + latest + enable