123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- using Utilities;
- namespace ISCSIConsole
- {
- public partial class Program
- {
- private static FileStream m_logFile;
- public static bool OpenLogFile(string logFilePath)
- {
- try
- {
-
-
- m_logFile = new FileStream(logFilePath, FileMode.Append, FileAccess.Write, FileShare.Read, 0x1000, FileOptions.WriteThrough);
- return true;
- }
- catch
- {
- return false;
- }
- }
- public static void CloseLogFile()
- {
- if (m_logFile != null)
- {
- lock (m_logFile)
- {
- m_logFile.Close();
- m_logFile = null;
- }
- }
- }
- public static void OnLogEntry(object sender, LogEntry entry)
- {
- if (m_logFile != null && entry.Severity != Severity.Trace)
- {
- lock (m_logFile)
- {
- StreamWriter writer = new StreamWriter(m_logFile);
- string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ");
- writer.WriteLine("{0} {1} [{2}] {3}", entry.Severity.ToString().PadRight(12), timestamp, entry.Source, entry.Message);
- writer.Flush();
- }
- }
- }
- }
- }
|