Given this code snippet:
public IEnumerable<IFileInfo> GetFiles(string searchPattern)
{
return this.DirectoryInfo
.GetFiles(searchPattern)
.Select(fileInfo => new FileInfoWrapper(fileInfo.FullName));
}
Suppose that the physical disk have bad sectors. This code is called wrapped into a try/catch
clause.
try
{
var files = this.GetFiles("*");
// ...
}
catch (IOException ex)
{
// This call writes a new entry on Windows EventLog
// - The text written is ex.Message plus ex.Stacktrace value in this case.
new LogEntry((int)GlobalEventLogId.FileIoError, ex)
{
Source = Assembly.GetExecutingAssembly().GetName().Name,
EntryType = LogEntryType.Error,
}.Write();
}
How can I determine what file is corrupt if the code raises IOException
with text: Data Error (Cyclic Rendundancy check)?