Next() private method

private Next ( TemplatedPathRoller roller, LogEventLevel level = null ) : RollingLogFile
roller TemplatedPathRoller
level LogEventLevel
return RollingLogFile
        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;
            }
        }
コード例 #2
0
        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;
            }
        }