Skip to content

Commit bd4d7dd

Browse files
committed
Including the RollingFileSink initialization in the try..catch so that any errors in the creation are included in the self log
1 parent 7cf84eb commit bd4d7dd

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/Serilog.Sinks.File/FileLoggerConfigurationExtensions.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -528,13 +528,13 @@ static LoggerConfiguration ConfigureFile(
528528

529529
ILogEventSink sink;
530530

531-
if (rollOnFileSizeLimit || rollingInterval != RollingInterval.Infinite)
531+
try
532532
{
533-
sink = new RollingFileSink(path, formatter, fileSizeLimitBytes, retainedFileCountLimit, encoding, buffered, shared, rollingInterval, rollOnFileSizeLimit, hooks, retainedFileTimeLimit);
534-
}
535-
else
536-
{
537-
try
533+
if (rollOnFileSizeLimit || rollingInterval != RollingInterval.Infinite)
534+
{
535+
sink = new RollingFileSink(path, formatter, fileSizeLimitBytes, retainedFileCountLimit, encoding, buffered, shared, rollingInterval, rollOnFileSizeLimit, hooks, retainedFileTimeLimit);
536+
}
537+
else
538538
{
539539
if (shared)
540540
{
@@ -546,16 +546,17 @@ static LoggerConfiguration ConfigureFile(
546546
{
547547
sink = new FileSink(path, formatter, fileSizeLimitBytes, encoding, buffered, hooks);
548548
}
549+
549550
}
550-
catch (Exception ex)
551-
{
552-
SelfLog.WriteLine("Unable to open file sink for {0}: {1}", path, ex);
551+
}
552+
catch (Exception ex)
553+
{
554+
SelfLog.WriteLine("Unable to open file sink for {0}: {1}", path, ex);
553555

554-
if (propagateExceptions)
555-
throw;
556+
if (propagateExceptions)
557+
throw;
556558

557-
return addSink(new NullSink(), LevelAlias.Maximum, null);
558-
}
559+
return addSink(new NullSink(), LevelAlias.Maximum, null);
559560
}
560561

561562
if (flushToDiskInterval.HasValue)

0 commit comments

Comments
 (0)