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