public void writeMsg(LogMsg msg) { string channelName = ""; switch(msg.channel){ case 0: channelName = "PANIC"; break; case 1: channelName = "ERROR"; break; case 2: channelName = "WARN"; break; case 3: channelName = "INFO"; break; case 4: channelName = "DEBUG"; break; case 5: channelName = "TRACE"; break; case 6: channelName = "SQLTRACE"; break; } // If we're not lazy logging, then log to the console: Console.WriteLine ("{0:yyyy/MM/dd HH:mm:ss.fff}|{1}|{2}|{3}|{4}|{5}", msg.timestamp, // {0} msg.tid, // {1} msg.file, // {2} msg.line, // {3} channelName, // {4} msg.msg // {5} ); }
public static LogMsg PrepareMsg(int channel, string message, params object[] options) { LogMsg lm = new LogMsg (); lm.channel = channel; lm.msg = String.Format (message, options); if (lm.msg.Length == message.Length) { lm.msg_static = true; } StackTrace st = new StackTrace (new StackFrame (true)); StackFrame sf = st.GetFrame (2); // 0 is us, 1 is the Panic,Debug,etc. method above, 2 is the original caller lm.file = sf.GetFileName (); lm.line = sf.GetFileLineNumber (); return lm; }
void AddForwardMsg(LogMsg lm) { LogPrint("AdaptiveLogs::AddForwardMsg(LogMsg* lm)"); using(EnEx ee = new EnEx("AdaptiveLogs::AddForwardMsg(LogMsg* lm)")){ if(!m_logForwarding){ return; } string logxml = "<LogObj id=\"0\" file=\"{0}\" line=\"{1}\" tid=\"{2}\" timestamp_a=\"{3}\"" + " timestamp_b=\"{4}\" timestamp_c=\"\" channel=\"{5}\" appName=\"{6}\" machineName=\"{7}\">" + "<msg><![CDATA[{8}]]></msg></LogObj>"; var msgBytes = System.Text.Encoding.UTF8.GetBytes( lm.msg ); string xml = String.Format( logxml, lm.file, lm.line, lm.tid, lm.timestamp.ToFileTime(), lm.timestamp.Millisecond, lm.channel, lm.appName, lm.machineName, System.Convert.ToBase64String(msgBytes) ); m_forwardMsg += xml; } }
public void WriteLogMsg(LogMsg lm) { LogPrint("AdaptiveLogs::WriteLogMsg(LogMsg* lm)"); using(EnEx ee = new EnEx("AdaptiveLogs::WriteLogMsg(LogMsg* lm)")){ try { m_log_stage.Add( lm ); m_file.writeMsg( m_log_stage ); } catch (Exception e){ Console.Write("Caught exeption during write:\n{0}\n{1}\n", e.Message, e.StackTrace ); // If anything goes wrong writing this message to the log file, simply close // the log file and start a new one. try { m_file.createNewFile(); m_file.writeMsg( m_log_stage ); } catch(Exception e2){ Console.Write("Badnews! 2nd exception caught trying to log:\n{0}\n{1}\n", e2.Message, e2.StackTrace ); try { m_file.close(); m_file = new LogFile2( m_file_name, m_max_file_size); } catch (Exception e3){ Console.Write("Panic! 3rd exception caught trying to log:\n{0}\n{1}\n", e3.Message, e3.StackTrace ); throw e3; } } } ClearStage(); AddForwardMsg( lm ); } }
public void ProcessMessage(LogMsg msg) { LogPrint ("AdaptiveLogs::ProcessMessage(LogMsg lm)"); using (EnEx ee = new EnEx ("AdaptiveLogs::ProcessMessage(LogMsg lm)")) { // find the parameters based on the channel if(msg.channel < 0 || msg.channel >= m_log_parms.Count){ // bad channel number on the log, throw it away. return; } AdaptiveLogParm alp = m_log_parms[msg.channel]; // If it's not on and not buffered, then throw it away if(alp.onoff == false && alp.buffer_when_off == false){ return; } // if it's not on, but buffered, then add it to the buffer if(alp.onoff == false && alp.buffer_when_off == true){ AddLogToBuffer(msg); return; } // if it's on: if(alp.onoff){ // Initialize our forwarding message InitForwardMsg(); // tail the buffer by dump_when_hit BufferTail(alp.dump_when_hit); // Write the log message out WriteLogMsg(msg); // Empty the buffer, 'cause they're all out of order now. ClearBuffer(); // Send our forwarding message SendForwardMsg(); } } }
public void AddLogToBuffer(LogMsg lm) { LogPrint("AdaptiveLogs::AddLogToBuffer(LogMsg* lm)"); using(EnEx ee = new EnEx("AdaptiveLogs::AddLogToBuffer(LogMsg* lm)")){ m_log_buffer.Add(lm); if(m_log_buffer.Count > m_max_buffer_size){ // delete the message on the front of the buffer. m_log_buffer.RemoveAt(0); } } }