public void WriteBadFormat() { string[] messageArray = new string[5]; string fullMessage = null; // We aren't checking the actual returns, just making sure these don't result in exceptions. // ToDo: Add logic to check that the result contains each item of data? fullMessage = CommonCentralLogic.SafeFormat(null, "This is a test\tof a bad format call\n{0}, {1}, {2}", "zero", 1); messageArray[0] = fullMessage; fullMessage = CommonCentralLogic.SafeFormat(null, "This is a test\r\nof a legal format call\t{0},\t{1},\t{2}", 0, null, "two"); messageArray[1] = fullMessage; fullMessage = CommonCentralLogic.SafeFormat(null, "This is a test\n\rof a bad format call\t{0},\t{1},\n{2}\t{3}", null, "one", "\"two\""); messageArray[2] = fullMessage; fullMessage = CommonCentralLogic.SafeFormat(null, null, 0, "\"null format test\"", 2); messageArray[3] = fullMessage; fullMessage = CommonCentralLogic.SafeFormat(null, string.Empty, "empty\rformat\ntest", 1); messageArray[4] = fullMessage; Log.Trace("This is a test\tof a bad format call to Log.Trace()\n{0}, {1}, {2}", "zero", 1); Log.Trace("This is a test\r\nof a legal format call to Log.Trace()\t{0},\t{1},\t{2}", 0, null, "two"); Log.Trace("This is a test\n\rof a bad format call to Log.Trace()\t{0},\t{1},\n{2}\t{3}", null, "one", "\"two\""); Log.Trace((string)null, 0, "null format test", 2); Log.Trace(string.Empty, "empty format test", 1); Thread.Sleep(2000); // Give it time to put stuff in the log. return; }
public MessageSourceProvider(int skipFrames) { CommonCentralLogic.FindMessageSource(skipFrames + 1, true, null, out m_ClassName, out m_MethodName, out m_FileName, out m_LineNumber); OnMessageSourceCalculate(ref m_ClassName, ref m_MethodName, ref m_FileName, ref m_LineNumber); }
/// <summary> /// Construct an ExceptionSourceProvider based on a provided Exception. /// </summary> /// <remarks>The first (closest) stack frame of the first (outer) Exception will be taken as the /// originator of a log message using this as its IMessageSourceProvider.</remarks> /// <param name="exception">The Exception whose first stack frame is the declared originator.</param> public ExceptionSourceProvider(Exception exception) { // We never skipped Gibraltar frames here, so go ahead with trustSkipFrames = true to disable that check. CommonCentralLogic.FindMessageSource(0, true, exception, out m_ClassName, out m_MethodName, out m_FileName, out m_LineNumber); OnMessageSourceCalculate(ref m_ClassName, ref m_MethodName, ref m_FileName, ref m_LineNumber); }
public MessageSourceProvider(int skipFrames, bool localOrigin) { const bool trustSkipFrames = true; // Set true to trust skipFrames count and don't skip over Gibraltar libs. // ReSharper disable ConditionIsAlwaysTrueOrFalse CommonCentralLogic.FindMessageSource(skipFrames + 1, localOrigin || trustSkipFrames, null, out m_ClassName, out m_MethodName, out m_FileName, out m_LineNumber); // ReSharper restore ConditionIsAlwaysTrueOrFalse }