Skip to content

Commit

Permalink
Use ArgumentNullException.ThrowIfNull instead of if statements for nu…
Browse files Browse the repository at this point in the history
…ll check (#46)
  • Loading branch information
Revazashvili authored Dec 20, 2024
1 parent 182acc9 commit e48e9af
Showing 1 changed file with 4 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ public static class ClientInfoLoggerConfigurationExtensions
public static LoggerConfiguration WithClientIp(
this LoggerEnrichmentConfiguration enrichmentConfiguration)
{
if (enrichmentConfiguration == null)
{
throw new ArgumentNullException(nameof(enrichmentConfiguration));
}
ArgumentNullException.ThrowIfNull(enrichmentConfiguration, nameof(enrichmentConfiguration));

return enrichmentConfiguration.With<ClientIpEnricher>();
}
Expand All @@ -47,10 +44,7 @@ public static LoggerConfiguration WithCorrelationId(
string headerName = "x-correlation-id",
bool addValueIfHeaderAbsence = false)
{
if (enrichmentConfiguration == null)
{
throw new ArgumentNullException(nameof(enrichmentConfiguration));
}
ArgumentNullException.ThrowIfNull(enrichmentConfiguration, nameof(enrichmentConfiguration));

return enrichmentConfiguration.With(new CorrelationIdEnricher(headerName, addValueIfHeaderAbsence));
}
Expand All @@ -67,15 +61,8 @@ public static LoggerConfiguration WithCorrelationId(
public static LoggerConfiguration WithRequestHeader(this LoggerEnrichmentConfiguration enrichmentConfiguration,
string headerName, string propertyName = null)
{
if (enrichmentConfiguration == null)
{
throw new ArgumentNullException(nameof(enrichmentConfiguration));
}

if (headerName == null)
{
throw new ArgumentNullException(nameof(headerName));
}
ArgumentNullException.ThrowIfNull(enrichmentConfiguration, nameof(enrichmentConfiguration));
ArgumentNullException.ThrowIfNull(headerName, nameof(headerName));

return enrichmentConfiguration.With(new ClientHeaderEnricher(headerName, propertyName));
}
Expand Down

0 comments on commit e48e9af

Please sign in to comment.