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

Enable nullability annotations in the project #56

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Serilog.Enrichers
{
public abstract class CachedPropertyEnricher: ILogEventEnricher
{
private LogEventProperty _cachedProperty { get; set; }
private LogEventProperty? _cachedProperty { get; set; }

/// <summary>
/// Enrich the log event.
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class EnvironmentVariableEnricher : CachedPropertyEnricher
/// </summary>
public string EnvironmentVariablePropertyName { get; }

public EnvironmentVariableEnricher(string envVarName, string propertyName)
public EnvironmentVariableEnricher(string envVarName, string? propertyName)
{
_envVarName = envVarName;
EnvironmentVariablePropertyName = propertyName ?? envVarName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static LoggerConfiguration WithEnvironmentUserName(
/// <param name="propertyName">The Optional name of the property. If empty <see cref="environmentVariableName"/> is used</param>
/// <returns>Configuration object allowing method chaining.</returns>
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<RepositoryUrl>https://github.com/serilog/serilog-enrichers-environment</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down