Example #1
0
 private void EnsureStreamIsOpen()
 {
     if (this.m_Stream == null)
     {
         this.m_Stream = this.GetStream();
     }
 }
Example #2
0
 private void CloseCurrentStream()
 {
     if (this.m_Stream != null)
     {
         Dictionary<string, ReferencedStream> streams = m_Streams;
         lock (streams)
         {
             this.m_Stream.CloseStream();
             if (!this.m_Stream.IsInUse)
             {
                 m_Streams.Remove(this.m_FullFileName.ToUpper(CultureInfo.InvariantCulture));
             }
             this.m_Stream = null;
         }
     }
 }
Example #3
0
 private ReferencedStream GetStream()
 {
     int num = 0;
     ReferencedStream stream2 = null;
     string fullPath = Path.GetFullPath(this.LogFileName + ".log");
     while ((stream2 == null) && (num < 0x7fffffff))
     {
         string str3;
         if (num == 0)
         {
             str3 = Path.GetFullPath(this.LogFileName + ".log");
         }
         else
         {
             str3 = Path.GetFullPath(this.LogFileName + "-" + num.ToString(CultureInfo.InvariantCulture) + ".log");
         }
         string key = str3.ToUpper(CultureInfo.InvariantCulture);
         Dictionary<string, ReferencedStream> streams = m_Streams;
         lock (streams)
         {
             if (m_Streams.ContainsKey(key))
             {
                 stream2 = m_Streams[key];
                 if (!stream2.IsInUse)
                 {
                     m_Streams.Remove(key);
                     stream2 = null;
                 }
                 else
                 {
                     if (this.Append)
                     {
                         new FileIOPermission(FileIOPermissionAccess.Write, str3).Demand();
                         stream2.AddReference();
                         this.m_FullFileName = str3;
                         return stream2;
                     }
                     num++;
                     stream2 = null;
                     continue;
                 }
             }
             System.Text.Encoding fileEncoding = this.Encoding;
             try
             {
                 if (this.Append)
                 {
                     fileEncoding = this.GetFileEncoding(str3);
                     if (fileEncoding == null)
                     {
                         fileEncoding = this.Encoding;
                     }
                 }
                 StreamWriter stream = new StreamWriter(str3, this.Append, fileEncoding);
                 stream2 = new ReferencedStream(stream);
                 stream2.AddReference();
                 m_Streams.Add(key, stream2);
                 this.m_FullFileName = str3;
                 return stream2;
             }
             catch (IOException)
             {
             }
             num++;
             continue;
         }
     }
     throw ExceptionUtils.GetInvalidOperationException("ApplicationLog_ExhaustedPossibleStreamNames", new string[] { fullPath });
 }