public override Stream AcquireLock() { if (m_stream == null) { try { using (CurrentAppender.SecurityContext.Impersonate(this)) { string directoryFullName = Path.GetDirectoryName(m_filename); if (!Directory.Exists(directoryFullName)) { Directory.CreateDirectory(directoryFullName); } if (c_stream == null) { c_stream = ConcurrentStream.GetInstance(m_filename, m_append, FileAccess.Write, FileShare.Read); c_stream.IsOpen = true; } m_stream = c_stream; m_append = true; } } catch (Exception e1) { CurrentAppender.ErrorHandler.Error("Unable to acquire lock on file " + m_filename + ". " + e1.Message); } } return(m_stream); }
public static ConcurrentStream GetInstance(string path, bool append, FileAccess access, FileShare share) { if (instance == null) { instance = new ConcurrentStream(path, append, access, share); } return(instance); }