Пример #1
0
        public override Stream AcquireLock()
        {
            if (_stream == null)
            {
                try
                {
                    using (CurrentAppender.SecurityContext.Impersonate(this))
                    {
                        var directoryFullName = Path.GetDirectoryName(_filename);
                        if (directoryFullName != null && !Directory.Exists(directoryFullName))
                        {
                            Directory.CreateDirectory(directoryFullName);
                        }

                        if (_concurrentStream == null)
                        {
                            _concurrentStream = ConcurrentStream.GetInstance(_filename, _append, FileAccess.Write, FileShare.Read);
                        }
                        _stream = _concurrentStream;
                        _append = true;
                    }
                }
                catch (Exception e1)
                {
                    CurrentAppender.ErrorHandler.Error("Unable to acquire lock on file " + _filename + ". " + e1.Message);
                }
            }
            return _stream;
        }
Пример #2
0
 public static ConcurrentStream GetInstance(string path,
  bool append,
  FileAccess access,
  FileShare share)
 {
     if (_instance != null) return _instance;
     _instance = new ConcurrentStream(path, append, access, share);
     return _instance;
 }