public static void TraceMessage( Activity activity, string message, MessageType type = MessageType.Trace, IDictionary<string, string> keywords = null, bool logLocallyOnly = false #if TRACE , [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0 #endif ) { // TODO: Implement logging var traceInfo = default(string); #if TRACE traceInfo = string.Format("[caller: {2} in {0}, line {1}]", Path.GetFileName(sourceFilePath), sourceLineNumber, memberName); #endif var formattedMessage = string.Format("[LOG][{1}] {0} {2}{3}", message, type, keywords.ToLogString(), traceInfo); if (activity != Activity.Info || WriteInfoToConsole) { Debug.WriteLine(formattedMessage); Console.WriteLine(formattedMessage); } if (!logLocallyOnly) { Log.WriteToStorageList(activity, message); } }
public static void ExceptionMessage( Exception exception, Activity activity, string message = null, MessageType type = MessageType.Exception, IDictionary<string, string> keywords = null, bool logLocallyOnly = false, [CallerMemberName] string memberName = "") { // TODO: Implement logging if ((type & MessageType.Exception) != MessageType.Exception) { type |= MessageType.Exception; } var formattedMessage = string.Format( "[LOG][{1}] {0} ({3}) {2}[caller: {4}]", message, type, keywords.ToLogString(), exception.Message, memberName); // TODO aggregate exceptions if ((type & MessageType.UserCodeException) == MessageType.UserCodeException) { formattedMessage = string.Format( "[LOG][{1}] {0} ({3}) {2}[caller: {4}]\n[details: {5}]\n---------------------------------------------------------------------------", message, type, keywords.ToLogString(), exception.Message, memberName, exception.ToString()); } if (activity != Activity.Info || WriteInfoToConsole) { Debug.WriteLine(formattedMessage); var oldColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(formattedMessage); Console.ForegroundColor = oldColor; } if (!logLocallyOnly) { Log.WriteToStorageList(activity, message); } }