/// <summary> /// Acquire a lock on the file. /// </summary> /// <returns></returns> public bool AcquireLock() { bool ret; lock (this) { if (!m_lockingModel.Locked) { // If lock is already acquired, nop if (m_lockingModel.AcquireLock()) { m_lockLevel = 1; m_realStream = m_lockingModel.Stream; try { if (m_realStream.Position > m_realStream.Length) { // if the file is rolled in another thread, our stream sees the updated stream length but the position IS NOT CHANGED // any further attempts to set the position causes an exception because the current position is beyond the end of the // file, so we must reopen the stream (which will put the cursor at the end of the file anyway) Reopen(); } else { if (m_realStream.CanSeek) { m_realStream.Seek(0, SeekOrigin.End); } } } catch (Exception e) { LogLog.Error(typeof(FileAppender), "FileAppender: INTERNAL ERROR. Unable to see file: " + e.Message); } ret = true; } else { ret = false; } } else { m_lockLevel++; ret = true; if (m_realStream == null) { m_realStream = m_lockingModel.Stream; } } } return(ret); }
public bool AcquireLock() { bool result = false; lock (this) { if (m_lockLevel == 0) { m_realStream = m_lockingModel.AcquireLock(); } if (m_realStream != null) { m_lockLevel++; return(true); } return(result); } }
public bool AcquireLock() { bool ret = false; lock (this) { if (m_lockLevel == 0) { // If lock is already acquired, nop m_realStream = m_lockingModel.AcquireLock(); } if (m_realStream != null) { m_lockLevel++; ret = true; } } return(ret); }