Example #1
0
 public void FlushAllStreams()
 {
     using (Locker.AcquireReaderLock(_lock))
     {
         foreach (var stream in _streamCache.Values)
         {
             stream.StreamWriter.Flush();
         }
     }
 }
Example #2
0
        /// <summary>
        /// Return a stream writer for the passed path name
        /// </summary>
        /// <param name="path">The path name</param>
        /// <returns>An existing or new stream writer</returns>
        public StreamWriter GetStreamWriter(string path)
        {
            CachedStream cs = null;

            using (Locker.AcquireReaderLock(_lock))
            {
                if (!_streamCache.TryGetValue(path, out cs))
                {
                    using (Locker.UpgradeToWriterLock(_lock))
                    {
                        Stream stream = GetStream(path);
                        cs = new CachedStream()
                        {
                            StreamWriter = new StreamWriter(stream)
                        };
                        _streamCache.Add(path, cs);
                    }
                }
            }

            cs.LastAccessTime = DateTime.Now;
            return(cs.StreamWriter);
        }