public m0Logger(m0LogDestination dest) { m_logdest = dest; m_debuglevel = 0; if (m_logdest == m0LogDestination.LOG_EVENTLOG) { try { m_eventLog = new System.Diagnostics.EventLog(); if (!System.Diagnostics.EventLog.SourceExists("modzero")) { System.Diagnostics.EventLog.CreateEventSource( "modzero", "Application"); } m_eventLog.Source = "modzero"; m_eventLog.Log = "Application"; } catch (Exception e) { m_logdest = m0LogDestination.LOG_CONSOLE; Console.WriteLine("[e] m0Logger: failed to initialize eventlog: " + e.Message); } } else if (m_logdest == m0LogDestination.LOG_FILE) { init_filelogging("modzero_debug.log"); } else { } }
private void init_filelogging(String filename) { String logdir = System.Environment.GetFolderPath( Environment.SpecialFolder.LocalApplicationData) + "\\modzero\\debug"; m_logfile = Path.Combine(logdir, filename); try { if (!Directory.Exists(logdir)) { Directory.CreateDirectory(logdir); } m_logdest = m0LogDestination.LOG_FILE; } catch (Exception e) { Console.WriteLine("[e] failed to create logdir. falling back to Console logging: " + e.Message); m_logdest = m0LogDestination.LOG_CONSOLE; } }
private void append_log(String msg) { StreamWriter sw = null; try { sw = File.AppendText(m_logfile); sw.WriteLine(msg); sw.Flush(); } catch (Exception e) { Console.WriteLine("[e] failed to write to logfile. falling back to Console logging: " + e.Message); m_logdest = m0LogDestination.LOG_CONSOLE; } finally { if (sw != null) { sw.Close(); } } }
public m0Logger() { m_logdest = m0LogDestination.LOG_CONSOLE; m_debuglevel = 0; }
public m0Logger(m0LogDestination dest, TextBox tb) { m_logdest = dest; m_debuglevel = 1; m_textbox = tb; }
public m0Logger(m0LogDestination dest, String filename) { m_logdest = dest; m_debuglevel = 0; init_filelogging(filename); }