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

Reject Empty path values #258

Closed
wants to merge 4 commits into from
Closed
Changes from 2 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
16 changes: 9 additions & 7 deletions src/Serilog.Sinks.File/FileLoggerConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,10 @@ public static LoggerConfiguration File(
TimeSpan? retainedFileTimeLimit = null)
{
if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration));
if (path == null) throw new ArgumentNullException(nameof(path));
if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate));

// check if null or empty on these.
bartelink marked this conversation as resolved.
Show resolved Hide resolved
AraHaan marked this conversation as resolved.
Show resolved Hide resolved
if (string.IsNullOrEmpty(path)) throw new ArgumentNullException(nameof(path));
if (string.IsNullOrEmpty(outputTemplate)) throw new ArgumentNullException(nameof(outputTemplate));
AraHaan marked this conversation as resolved.
Show resolved Hide resolved

var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);
return File(sinkConfiguration, formatter, path, restrictedToMinimumLevel, fileSizeLimitBytes,
Expand Down Expand Up @@ -337,7 +339,7 @@ public static LoggerConfiguration File(
{
if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration));
if (formatter == null) throw new ArgumentNullException(nameof(formatter));
if (path == null) throw new ArgumentNullException(nameof(path));
if (string.IsNullOrEmpty(path)) throw new ArgumentNullException(nameof(path));
AraHaan marked this conversation as resolved.
Show resolved Hide resolved

return ConfigureFile(sinkConfiguration.Sink, formatter, path, restrictedToMinimumLevel, fileSizeLimitBytes, levelSwitch,
buffered, false, shared, flushToDiskInterval, encoding, rollingInterval, rollOnFileSizeLimit,
Expand Down Expand Up @@ -449,8 +451,8 @@ public static LoggerConfiguration File(
FileLifecycleHooks? hooks = null)
{
if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration));
if (path == null) throw new ArgumentNullException(nameof(path));
if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate));
if (string.IsNullOrEmpty(path)) throw new ArgumentNullException(nameof(path));
if (string.IsNullOrEmpty(outputTemplate)) throw new ArgumentNullException(nameof(outputTemplate));
AraHaan marked this conversation as resolved.
Show resolved Hide resolved

var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);
return File(sinkConfiguration, formatter, path, restrictedToMinimumLevel, levelSwitch, encoding, hooks);
Expand Down Expand Up @@ -493,7 +495,7 @@ public static LoggerConfiguration File(
{
if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration));
if (formatter == null) throw new ArgumentNullException(nameof(formatter));
if (path == null) throw new ArgumentNullException(nameof(path));
if (string.IsNullOrEmpty(path)) throw new ArgumentNullException(nameof(path));
AraHaan marked this conversation as resolved.
Show resolved Hide resolved

return ConfigureFile(sinkConfiguration.Sink, formatter, path, restrictedToMinimumLevel, null, levelSwitch, false, true,
false, null, encoding, RollingInterval.Infinite, false, null, hooks, null);
Expand All @@ -519,7 +521,7 @@ static LoggerConfiguration ConfigureFile(
{
if (addSink == null) throw new ArgumentNullException(nameof(addSink));
if (formatter == null) throw new ArgumentNullException(nameof(formatter));
if (path == null) throw new ArgumentNullException(nameof(path));
if (string.IsNullOrEmpty(path)) throw new ArgumentNullException(nameof(path));
AraHaan marked this conversation as resolved.
Show resolved Hide resolved
if (fileSizeLimitBytes.HasValue && fileSizeLimitBytes < 1) throw new ArgumentException("Invalid value provided; file size limit must be at least 1 byte, or null.", nameof(fileSizeLimitBytes));
if (retainedFileCountLimit.HasValue && retainedFileCountLimit < 1) throw new ArgumentException("At least one file must be retained.", nameof(retainedFileCountLimit));
if (retainedFileTimeLimit.HasValue && retainedFileTimeLimit < TimeSpan.Zero) throw new ArgumentException("Negative value provided; retained file time limit must be non-negative.", nameof(retainedFileTimeLimit));
Expand Down