Skip to content

Commit 771be4f

Browse files
authored
Merge pull request #196 from pvandervelde/fix-192
Including the RollingFileSink initialization in the try..catch; fixes #192
2 parents 7cf84eb + bd4d7dd commit 771be4f

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/Serilog.Sinks.File/FileLoggerConfigurationExtensions.cs

+14-13
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)