Skip to content

Commit

Permalink
Check for directory existence before attempting access.
Browse files Browse the repository at this point in the history
Stops exception from being thrown and tripping breakpoints when debugging application code.
  • Loading branch information
billrob committed Mar 13, 2019
1 parent ab9fc9f commit fca6eb9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Serilog.Sinks.File/Sinks/File/RollingFileSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,11 @@ void OpenFile(DateTime now, int? minSequence = null)
var existingFiles = Enumerable.Empty<string>();
try
{
existingFiles = Directory.GetFiles(_roller.LogFileDirectory, _roller.DirectorySearchPattern)
if (Directory.Exists(_roller.LogFileDirectory))
{
existingFiles = Directory.GetFiles(_roller.LogFileDirectory, _roller.DirectorySearchPattern)
.Select(Path.GetFileName);
}
}
catch (DirectoryNotFoundException) { }

Expand Down

0 comments on commit fca6eb9

Please sign in to comment.