/// <summary> /// Writes one formatted line to log file /// </summary> /// <param name="ClassName">Name of the sender class</param> /// <param name="FunctionName">Name of the sender function</param> /// <param name="Message">Message to log</param> /// <param name="Source">Source of error, if exists</param> /// <param name="MsgLevel">Message level (Info, Warning or Error)</param> private static bool WriteToLog(string ClassName, string FunctionName, string Message, string Source, TraceMsgLevel MsgLevel) { // Test if Trace service is already initialized if (m_TraceServiceIsRunning == false) { // If owner no exist, use apropriate function. if (Create(TraceLog.Directory + "TraceLog.txt") == false) { return(false); } // Write log header WriteHeader(); // Write Trace service to Enabled m_TraceServiceIsRunning = true; } // Get apropriate message level string TraceMsg = TranslateMsgLevel(MsgLevel); // Write output to log Trace.WriteLine("==> " + TraceMsg + " message has been raised from application. Details are :"); Trace.WriteLine("Class : " + ClassName); Trace.WriteLine("Function : " + FunctionName); Trace.WriteLine("Error source : " + (Source == "" ? "None" : Source)); Trace.WriteLine("Message : " + Message); Trace.WriteLine(""); return(true); }
/// <summary> /// Translate Message Level to string /// </summary> /// <param name="MsgLevel">The MEssage level to translate</param> /// <returns>The apropriate string</returns> private static string TranslateMsgLevel(TraceMsgLevel MsgLevel) { // Translate apropiate level message switch (MsgLevel) { case TraceMsgLevel.Message: { return("Info"); } case TraceMsgLevel.Warning: { return("Warning"); } case TraceMsgLevel.Error: { return("Error"); } default: { return("Unknown info type"); } } }
/// <summary> /// Write a line into log file /// </summary> /// <param name="ClassName">Name of the sender class</param> /// <param name="FunctionName">Name of the sender function</param> /// <param name="Message">Message to log</param> /// <param name="Source">Source of error, if exists</param> /// <param name="MsgLevel">Message level (Info, Warning or Error)</param> /// <param name="Switch">Switch to control the log statement</param> public static void Write(string ClassName, string FunctionName, string Message, string Source, TraceMsgLevel MsgLevel, TraceSwitch Switch) { // Test if switch is enabled if (Switch.Level != 0) { // Write infos to log file. WriteToLog(ClassName, FunctionName, Message, Source, MsgLevel); } }