Write() public method

Writes the specified log to the file
public Write ( LogMessage log, bool autoFlush = true ) : void
log LogMessage
autoFlush bool
return void
Exemplo n.º 1
0
 public void Save(LogFileWriter fileWriter)
 {
     foreach (var message in AllMessages)
     {
         if (message.Message != null)
         {
             fileWriter.Write(message.Message);
         }
     }
 }
Exemplo n.º 2
0
        private void WriteLogMessage(LogMessage log)
        {
            //Rollover a file if over 500KB in size, over 50000 records, or older than 12 hours.
            //Ideally, 500KB will always come first.
            if (m_writer != null && (m_writer.LogSize > 500 * 1024 || m_writer.LogCount >= 50000 || m_fileAge.Elapsed.TotalHours > 12))
            {
                string fileName = m_writer.FileName;
                m_writer.Dispose();
                m_writer = null;
                OnNewFileComplete(fileName);
            }

            if (m_writer == null)
            {
                m_fileAge.Restart();
                try
                {
                    if (m_maxFileCount > 0)
                    {
                        string[] files = Directory.GetFiles(m_path, "*.logz");
                        if (files.Length > m_maxFileCount)
                        {
                            Array.Sort(files);

                            for (int x = 0; x < files.Length - m_maxFileCount; x++)
                            {
                                File.Delete(files[x]);
                            }
                        }
                    }
                }
                catch (Exception)
                {
                }
                string file = $"{DateTime.UtcNow.ToString("yyyyMMdd-HHmmss-ffffff")} - {m_processName} - {m_fileSequenceNumber}.logz";
                m_fileSequenceNumber++;
                var fileName = Path.Combine(m_path, file);
                m_writer = new LogFileWriter(fileName);
            }

            m_writer.Write(log, false);
        }
 public void Save(LogFileWriter fileWriter)
 {
     foreach (var message in AllMessages)
     {
         if (message.Message != null)
         {
             fileWriter.Write(message.Message);
         }
     }
 }