/// <summary> /// Logs the 'Before Action' info (The method being called and it's properties/parameters). /// </summary> /// <param name="properties">(Optional) A collection of properties to log ("Method Name" and "Stack Caller" are automatically generated so do not include).</param> public static void BeforeAction(OrderedDictionary properties = null) { // Get the padding (if any) to prepend to the log line LogPadding logPadding = new LogPadding(new StackTrace().GetFrame(2).GetMethod().ReflectedType); // Get the method name (of the method that called this one) from the stack string methodName = new StackTrace().GetFrame(1).GetMethod().ReflectedType + "." + new StackTrace().GetFrame(1).GetMethod().Name + "()"; // Get that method's caller from the stack string stackCaller = new StackTrace().GetFrame(2).GetMethod().ReflectedType + "." + new StackTrace().GetFrame(2).GetMethod().Name + "()"; // Write the method name Log.WriteLine(logPadding.Padding + methodName); if (properties != null) { // Parse the Dictionary (for properties of the method being logged) foreach (DictionaryEntry entry in properties) { // Write the property to the log Log.WriteLine(logPadding.InfoPadding + "[INFO] " + entry.Key + " : " + entry.Value); } } // Write the stack caller to the log Log.WriteLine(logPadding.InfoPadding + "[STACK] Caller: " + stackCaller); }
/// <summary> /// A convenience method for logging a "[RESULT] Failure: {message}". /// </summary> /// <param name="message">(Optional) The message to display in the log's Result line.</param> /// <param name="exception"></param> public static void Failure(string message = "", Exception exception = null) { // Get the padding (if any) LogPadding logPadding = new LogPadding(new StackTrace().GetFrame(2).GetMethod().ReflectedType); // Write the line to the log if (message != "") { WriteLine(logPadding.Padding + "[RESULT] Failure: " + message); } else if (exception != null) { WriteLine(logPadding.Padding + "[RESULT] Failure: " + exception.Message); } else { WriteLine(logPadding.Padding + "[RESULT] Failure!"); } // If there is no padding, then write an end line to sepearte the actions in the log if (logPadding.Padding == "") { Log.WriteLine(); } }