From 2b188c4ac9040b93ceb3720ec59bf22d78e33f13 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Mon, 6 Aug 2012 09:21:14 -0400 Subject: [PATCH] Fixed string formatting in logger --- MediaBrowser.Common/Logging/BaseLogger.cs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/MediaBrowser.Common/Logging/BaseLogger.cs b/MediaBrowser.Common/Logging/BaseLogger.cs index 04c3b8097..c7c63d55e 100644 --- a/MediaBrowser.Common/Logging/BaseLogger.cs +++ b/MediaBrowser.Common/Logging/BaseLogger.cs @@ -26,7 +26,7 @@ namespace MediaBrowser.Common.Logging public void LogException(string message, Exception exception, params object[] paramList) { StringBuilder builder = new StringBuilder(); - + if (exception != null) { builder.AppendFormat("Exception. Type={0} Msg={1} StackTrace={3}{2}", @@ -36,7 +36,7 @@ namespace MediaBrowser.Common.Logging Environment.NewLine); } - message = string.Format(message, paramList); + message = FormatMessage(message, paramList); LogError(string.Format("{0} ( {1} )", message, builder)); } @@ -46,11 +46,24 @@ namespace MediaBrowser.Common.Logging LogEntry(message, LogSeverity.Warning, paramList); } + private string FormatMessage(string message, params object[] paramList) + { + if (paramList != null) + { + for (int i = 0; i < paramList.Length; i++) + { + message = message.Replace("{" + i + "}", paramList[i].ToString()); + } + } + + return message; + } + private void LogEntry(string message, LogSeverity severity, params object[] paramList) { if (severity < LogSeverity) return; - - message = string.Format(message, paramList); + + message = FormatMessage(message, paramList); Thread currentThread = Thread.CurrentThread;