Skip to content

Commit c394579

Browse files
committed
Enable nullability annotations in the project
1 parent c6f5a60 commit c394579

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

src/Serilog.Enrichers.Environment/Enrichers/CachedPropertyEnricher.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Serilog.Enrichers
1919
{
2020
public abstract class CachedPropertyEnricher: ILogEventEnricher
2121
{
22-
private LogEventProperty _cachedProperty { get; set; }
22+
private LogEventProperty? _cachedProperty { get; set; }
2323

2424
/// <summary>
2525
/// Enrich the log event.
@@ -35,8 +35,7 @@ private LogEventProperty GetLogEventProperty(ILogEventPropertyFactory propertyFa
3535
{
3636
// Don't care about thread-safety, in the worst case the field gets overwritten and one
3737
// property will be GCed
38-
if (_cachedProperty == null)
39-
_cachedProperty = CreateProperty(propertyFactory);
38+
_cachedProperty ??= CreateProperty(propertyFactory);
4039

4140
return _cachedProperty;
4241
}

src/Serilog.Enrichers.Environment/Enrichers/EnvironmentVariableEnricher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class EnvironmentVariableEnricher : CachedPropertyEnricher
3131
/// </summary>
3232
public string EnvironmentVariablePropertyName { get; }
3333

34-
public EnvironmentVariableEnricher(string envVarName, string propertyName)
34+
public EnvironmentVariableEnricher(string envVarName, string? propertyName)
3535
{
3636
_envVarName = envVarName;
3737
EnvironmentVariablePropertyName = propertyName ?? envVarName;

src/Serilog.Enrichers.Environment/EnvironmentLoggerConfigurationExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static LoggerConfiguration WithEnvironmentUserName(
6969
/// <param name="propertyName">The Optional name of the property. If empty <see cref="environmentVariableName"/> is used</param>
7070
/// <returns>Configuration object allowing method chaining.</returns>
7171
public static LoggerConfiguration WithEnvironmentVariable(
72-
this LoggerEnrichmentConfiguration enrichmentConfiguration, string environmentVariableName, string propertyName = null)
72+
this LoggerEnrichmentConfiguration enrichmentConfiguration, string environmentVariableName, string? propertyName = null)
7373
{
7474
if (enrichmentConfiguration == null) throw new ArgumentNullException(nameof(enrichmentConfiguration));
7575
var environmentVariableEnricher = new EnvironmentVariableEnricher(environmentVariableName, propertyName);

src/Serilog.Enrichers.Environment/Serilog.Enrichers.Environment.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<RepositoryUrl>https://github.com/serilog/serilog-enrichers-environment</RepositoryUrl>
1818
<RepositoryType>git</RepositoryType>
1919
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
20+
<LangVersion>latest</LangVersion>
21+
<Nullable>enable</Nullable>
2022
</PropertyGroup>
2123

2224
<ItemGroup>

0 commit comments

Comments
 (0)