コード例 #1
0
ファイル: H写文件.cs プロジェクト: zergmk2/K_Basic
        private void CloseCurrentStream()
        {
            if (this.m_Stream == null)
            {
                return;
            }
            Dictionary <string, ReferencedStream> dictionary = m_Streams;
            bool lockTaken = false;

            try
            {
                Monitor.Enter(dictionary, ref lockTaken);
                if (this.m_Stream == null)
                {
                    return;
                }
                this.m_Stream.CloseStream();
                if (!this.m_Stream.IsInUse)
                {
                    m_Streams.Remove(this.FullLogFileName.ToUpper(CultureInfo.InvariantCulture));
                }
                this.m_Stream = null;
            }
            finally
            {
                if (lockTaken)
                {
                    Monitor.Exit(dictionary);
                }
            }
        }
コード例 #2
0
ファイル: H写文件.cs プロジェクト: zergmk2/K_Basic
 private void EnsureStreamIsOpen()
 {
     if (this.m_Stream != null)
     {
         return;
     }
     this.m_Stream = this.GetStream();
 }
コード例 #3
0
ファイル: H写文件.cs プロジェクト: zergmk2/K_Basic
        private ReferencedStream GetStream()
        {
            ReferencedStream referencedStream = null;

            while (referencedStream == null && num < int.MaxValue)
            {
                string str = num != 0 ? Path.GetFullPath(this.LogFileName + ".log1" + "." + num) : Path.GetFullPath(this.LogFileName + ".log1");
                if (File.Exists(str) && new FileInfo(str).Length + 10000 > this.MaxFileSize)
                {
                    ++num;
                    continue;
                }
                string key = str.ToUpper(CultureInfo.InvariantCulture);
                Dictionary <string, ReferencedStream> dictionary = m_Streams;
                bool lockTaken = false;
                try
                {
                    Monitor.Enter(dictionary, ref lockTaken);
                    if (m_Streams.ContainsKey(key))
                    {
                        referencedStream = m_Streams[key];
                        if (!referencedStream.IsInUse)
                        {
                            m_Streams.Remove(key);
                            referencedStream = null;
                        }
                        else if (this.Append)
                        {
                            new FileIOPermission(FileIOPermissionAccess.Write, str).Demand();
                            referencedStream.AddReference();
                            this.FullLogFileName = str;
                            return(referencedStream);
                        }
                        else
                        {
                            checked { ++num; }
                            referencedStream = null;
                            continue;
                        }
                    }
                    Encoding encoding = this.Encoding;
                    try
                    {
                        if (this.Append)
                        {
                            encoding = this.GetFileEncoding(str) ?? this.Encoding;
                        }
                        referencedStream = new ReferencedStream(new StreamWriter(str, this.Append, encoding));
                        referencedStream.AddReference();
                        m_Streams.Add(key, referencedStream);
                        this.FullLogFileName = str;
                        return(referencedStream);
                    }
                    catch (IOException)
                    {
                    }
                    checked { ++num; }
                }
                finally
                {
                    if (lockTaken)
                    {
                        Monitor.Exit(dictionary);
                    }
                }
            }
            throw new Exception("ApplicationLog_ExhaustedPossibleStreamNames");
        }