Example #1
0
        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
            {
            }
        }
Example #2
0
        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;
            }
        }
Example #3
0
        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();
                }
            }
        }
Example #4
0
 public m0Logger()
 {
     m_logdest    = m0LogDestination.LOG_CONSOLE;
     m_debuglevel = 0;
 }
Example #5
0
 public m0Logger(m0LogDestination dest, TextBox tb)
 {
     m_logdest    = dest;
     m_debuglevel = 1;
     m_textbox    = tb;
 }
Example #6
0
 public m0Logger(m0LogDestination dest, String filename)
 {
     m_logdest    = dest;
     m_debuglevel = 0;
     init_filelogging(filename);
 }