private StreamWriter OpenFileForWriting(string folderPath, RollingLogFile rollingLogFile, Encoding encoding) { EnsureDirectoryCreated(folderPath); try { currentLogFile = rollingLogFile; var fullPath = Path.Combine(folderPath, rollingLogFile.Filename); var stream = File.Open(fullPath, FileMode.Append, FileAccess.Write, FileShare.Read); return new StreamWriter(stream, encoding ?? Encoding.UTF8); } catch (IOException ex) { SelfLog.WriteLine("Error {0} while opening obsolete file {1}", ex, rollingLogFile.Filename); return OpenFileForWriting(folderPath, rollingLogFile.Next(roller), encoding); } catch (Exception ex) { SelfLog.WriteLine("Error {0} while opening obsolete file {1}", ex, rollingLogFile.Filename); throw; } }
private StreamWriter OpenFileForWriting(string folderPath, RollingLogFile rollingLogFile, Encoding encoding) { EnsureDirectoryCreated(folderPath); try { currentLogFile = rollingLogFile; var fullPath = Path.Combine(folderPath, rollingLogFile.Filename); var stream = File.Open(fullPath, FileMode.Append, FileAccess.Write, FileShare.Read); return(new StreamWriter(stream, encoding ?? Encoding.UTF8)); } catch (IOException ex) { SelfLog.WriteLine("Error {0} while opening obsolete file {1}", ex, rollingLogFile.Filename); return(OpenFileForWriting(folderPath, rollingLogFile.Next(roller), encoding)); } catch (Exception ex) { SelfLog.WriteLine("Error {0} while opening obsolete file {1}", ex, rollingLogFile.Filename); throw; } }