From e3484bdcc204ae39e0bfdf08e758012a048d539c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 17 Dec 2014 17:39:17 -0500 Subject: 3.0.5464.40000 --- .../BaseApplicationHost.cs | 33 +++++++++++----------- .../Logging/NLogger.cs | 13 ++++++++- .../Logging/NlogManager.cs | 8 +++++- 3 files changed, 36 insertions(+), 18 deletions(-) (limited to 'MediaBrowser.Common.Implementations') diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index 891a03d39..9e14d0ee8 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -294,19 +294,20 @@ namespace MediaBrowser.Common.Implementations public static void LogEnvironmentInfo(ILogger logger, IApplicationPaths appPaths, bool isStartup) { - if (isStartup) - { - logger.Info("Media Browser Server started"); - } + logger.LogMultiline("Media Browser", LogSeverity.Info, GetBaseExceptionMessage(appPaths)); + } - logger.Info("Command line: {0}", string.Join(" ", Environment.GetCommandLineArgs())); + protected static StringBuilder GetBaseExceptionMessage(IApplicationPaths appPaths) + { + var builder = new StringBuilder(); - logger.Info("Server: {0}", Environment.MachineName); - logger.Info("Operating system: {0}", Environment.OSVersion.ToString()); - logger.Info("Processor count: {0}", Environment.ProcessorCount); - logger.Info("64-Bit OS: {0}", Environment.Is64BitOperatingSystem); - logger.Info("64-Bit Process: {0}", Environment.Is64BitProcess); - logger.Info("Program data path: {0}", appPaths.ProgramDataPath); + builder.AppendLine(string.Format("Command line: {0}", string.Join(" ", Environment.GetCommandLineArgs()))); + + builder.AppendLine(string.Format("Operating system: {0}", Environment.OSVersion)); + builder.AppendLine(string.Format("Processor count: {0}", Environment.ProcessorCount)); + builder.AppendLine(string.Format("64-Bit OS: {0}", Environment.Is64BitOperatingSystem)); + builder.AppendLine(string.Format("64-Bit Process: {0}", Environment.Is64BitProcess)); + builder.AppendLine(string.Format("Program data path: {0}", appPaths.ProgramDataPath)); Type type = Type.GetType("Mono.Runtime"); if (type != null) @@ -314,13 +315,13 @@ namespace MediaBrowser.Common.Implementations MethodInfo displayName = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static); if (displayName != null) { - logger.Info("Mono: " + displayName.Invoke(null, null)); + builder.AppendLine("Mono: " + displayName.Invoke(null, null)); } - } - - logger.Info("Application Path: {0}", appPaths.ApplicationPath); + } + + builder.AppendLine(string.Format("Application Path: {0}", appPaths.ApplicationPath)); - logger.Info("*** When reporting issues please include the entire log file. ***".ToUpper()); + return builder; } protected virtual IJsonSerializer CreateJsonSerializer() diff --git a/MediaBrowser.Common.Implementations/Logging/NLogger.cs b/MediaBrowser.Common.Implementations/Logging/NLogger.cs index c87b58f70..29b618890 100644 --- a/MediaBrowser.Common.Implementations/Logging/NLogger.cs +++ b/MediaBrowser.Common.Implementations/Logging/NLogger.cs @@ -14,6 +14,8 @@ namespace MediaBrowser.Common.Implementations.Logging /// private readonly NLog.Logger _logger; + private readonly ILogManager _logManager; + /// /// The _lock object /// @@ -23,8 +25,10 @@ namespace MediaBrowser.Common.Implementations.Logging /// Initializes a new instance of the class. /// /// The name. - public NLogger(string name) + /// The log manager. + public NLogger(string name, ILogManager logManager) { + _logManager = logManager; lock (LockObject) { _logger = NLog.LogManager.GetLogger(name); @@ -96,6 +100,13 @@ namespace MediaBrowser.Common.Implementations.Logging var messageText = LogHelper.GetLogMessage(exception); + var prefix = _logManager.ExceptionMessagePrefix; + + if (!string.IsNullOrWhiteSpace(prefix)) + { + messageText.Insert(0, prefix); + } + LogMultiline(message, level, messageText); } diff --git a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs index b18c6b95a..77d9f80f9 100644 --- a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs +++ b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs @@ -34,6 +34,12 @@ namespace MediaBrowser.Common.Implementations.Logging /// The log file path. public string LogFilePath { get; private set; } + /// + /// Gets or sets the exception message prefix. + /// + /// The exception message prefix. + public string ExceptionMessagePrefix { get; set; } + /// /// Initializes a new instance of the class. /// @@ -159,7 +165,7 @@ namespace MediaBrowser.Common.Implementations.Logging /// ILogger. public ILogger GetLogger(string name) { - return new NLogger(name); + return new NLogger(name, this); } /// -- cgit v1.2.3