removed static logger

This commit is contained in:
LukePulverenti
2013-02-21 15:26:35 -05:00
parent 4019b9260b
commit ab1065a567
46 changed files with 424 additions and 211 deletions

View File

@@ -6,6 +6,7 @@ using System.ComponentModel.Composition;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Model.Logging;
namespace MediaBrowser.Common.Api.Logging
{
@@ -24,6 +25,17 @@ namespace MediaBrowser.Common.Api.Logging
get { return "LogFile"; }
}
/// <summary>
/// Initializes a new instance of the <see cref="LogFileWebSocketListener" /> class.
/// </summary>
/// <param name="logger">The logger.</param>
[ImportingConstructor]
public LogFileWebSocketListener([Import("logger")] ILogger logger)
: base(logger)
{
}
/// <summary>
/// Initializes the specified kernel.
/// </summary>

View File

@@ -1,5 +1,6 @@
using MediaBrowser.Common.Kernel;
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Tasks;
using System.Collections.Generic;
using System.ComponentModel.Composition;
@@ -22,7 +23,18 @@ namespace MediaBrowser.Common.Api.ScheduledTasks
{
get { return "ScheduledTasksInfo"; }
}
/// <summary>
/// Initializes a new instance of the <see cref="ScheduledTasksWebSocketListener" /> class.
/// </summary>
/// <param name="logger">The logger.</param>
[ImportingConstructor]
public ScheduledTasksWebSocketListener([Import("logger")] ILogger logger)
: base(logger)
{
}
/// <summary>
/// Gets the data to send.
/// </summary>

View File

@@ -1,4 +1,5 @@
using MediaBrowser.Common.Kernel;
using MediaBrowser.Model.Logging;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
@@ -19,6 +20,17 @@ namespace MediaBrowser.Common.Api
get { return "SystemInfo"; }
}
/// <summary>
/// Initializes a new instance of the <see cref="SystemInfoWebSocketListener" /> class.
/// </summary>
/// <param name="logger">The logger.</param>
[ImportingConstructor]
public SystemInfoWebSocketListener([Import("logger")] ILogger logger)
: base(logger)
{
}
/// <summary>
/// Gets the data to send.
/// </summary>

View File

@@ -1,4 +1,5 @@
using MediaBrowser.Common.Logging;
using MediaBrowser.Model.Logging;
using System;
using System.Threading.Tasks;
@@ -9,6 +10,11 @@ namespace MediaBrowser.Common.Events
/// </summary>
public static class EventHelper
{
/// <summary>
/// The logger
/// </summary>
private static readonly ILogger Logger = LogManager.GetLogger("EventHelper");
/// <summary>
/// Fires the event.
/// </summary>
@@ -27,7 +33,7 @@ namespace MediaBrowser.Common.Events
}
catch (Exception ex)
{
Logger.LogException("Error in event handler", ex);
Logger.ErrorException("Error in event handler", ex);
}
});
}
@@ -52,7 +58,7 @@ namespace MediaBrowser.Common.Events
}
catch (Exception ex)
{
Logger.LogException("Error in event handler", ex);
Logger.ErrorException("Error in event handler", ex);
}
});
}
@@ -74,7 +80,7 @@ namespace MediaBrowser.Common.Events
}
catch (Exception ex)
{
Logger.LogException("Error in event handler", ex);
Logger.ErrorException("Error in event handler", ex);
}
}
}
@@ -96,7 +102,7 @@ namespace MediaBrowser.Common.Events
}
catch (Exception ex)
{
Logger.LogException("Error in event handler", ex);
Logger.ErrorException("Error in event handler", ex);
}
}
}

View File

@@ -38,8 +38,6 @@ namespace MediaBrowser.Common.IO
{
if (!path.EndsWith("*", StringComparison.OrdinalIgnoreCase))
{
Logger.LogInfo("Handle came back invalid for {0}. This might be a network share. Since this is a directory we'll try appending " + Path.DirectorySeparatorChar + "*.", path);
NativeMethods.FindClose(handle);
handle = NativeMethods.FindFirstFileEx(Path.Combine(path, "*"), FINDEX_INFO_LEVELS.FindExInfoBasic, out data,

View File

@@ -143,7 +143,7 @@ namespace MediaBrowser.Common.Kernel
get
{
// Lazy load
LazyInitializer.EnsureInitialized(ref _configuration, ref _configurationLoaded, ref _configurationSyncLock, () => XmlSerializer.GetXmlConfiguration<TConfigurationType>(ApplicationPaths.SystemConfigurationFilePath));
LazyInitializer.EnsureInitialized(ref _configuration, ref _configurationLoaded, ref _configurationSyncLock, () => XmlSerializer.GetXmlConfiguration<TConfigurationType>(ApplicationPaths.SystemConfigurationFilePath, Logger));
return _configuration;
}
protected set
@@ -441,8 +441,6 @@ namespace MediaBrowser.Common.Kernel
AddLogTarget(logFile, "ApplicationLogFile");
Logging.Logger.LoggerInstance = Logging.LogManager.GetLogger("App");
OnLoggerLoaded();
}
@@ -590,7 +588,7 @@ namespace MediaBrowser.Common.Kernel
try
{
plugin.Initialize(this);
plugin.Initialize(this, Logging.LogManager.GetLogger(plugin.GetType().Name));
Logger.Info("{0} {1} initialized.", plugin.Name, plugin.Version);
}

View File

@@ -6,6 +6,7 @@ using System.Linq;
using System.Net.WebSockets;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Logging;
namespace MediaBrowser.Common.Kernel
{
@@ -38,6 +39,25 @@ namespace MediaBrowser.Common.Kernel
/// <returns>Task{`1}.</returns>
protected abstract Task<TReturnDataType> GetDataToSend(TStateType state);
/// <summary>
/// The logger
/// </summary>
protected ILogger Logger;
/// <summary>
/// Initializes a new instance of the <see cref="BasePeriodicWebSocketListener{TStateType}" /> class.
/// </summary>
/// <param name="logger">The logger.</param>
protected BasePeriodicWebSocketListener(ILogger logger)
{
if (logger == null)
{
throw new ArgumentNullException("logger");
}
Logger = logger;
}
/// <summary>
/// Processes the message internal.
/// </summary>
@@ -71,7 +91,7 @@ namespace MediaBrowser.Common.Kernel
var cancellationTokenSource = new CancellationTokenSource();
Logger.LogInfo("{1} Begin transmitting over websocket to {0}", message.Connection.RemoteEndPoint, GetType().Name);
Logger.Info("{1} Begin transmitting over websocket to {0}", message.Connection.RemoteEndPoint, GetType().Name);
var timer = new Timer(TimerCallback, message.Connection, Timeout.Infinite, Timeout.Infinite);
@@ -135,7 +155,7 @@ namespace MediaBrowser.Common.Kernel
}
catch (Exception ex)
{
Logger.LogException("Error sending web socket message {0}", ex, Name);
Logger.ErrorException("Error sending web socket message {0}", ex, Name);
DisposeConnection(tuple);
}
finally
@@ -167,7 +187,7 @@ namespace MediaBrowser.Common.Kernel
/// <param name="connection">The connection.</param>
private void DisposeConnection(Tuple<WebSocketConnection, CancellationTokenSource, Timer, TStateType, SemaphoreSlim> connection)
{
Logger.LogInfo("{1} stop transmitting over websocket to {0}", connection.Item1.RemoteEndPoint, GetType().Name);
Logger.Info("{1} stop transmitting over websocket to {0}", connection.Item1.RemoteEndPoint, GetType().Name);
try
{

View File

@@ -1,89 +0,0 @@
using MediaBrowser.Model.Logging;
using System;
namespace MediaBrowser.Common.Logging
{
/// <summary>
/// Class Logger
/// </summary>
public static class Logger
{
/// <summary>
/// Gets or sets the logger instance.
/// </summary>
/// <value>The logger instance.</value>
internal static ILogger LoggerInstance { get; set; }
/// <summary>
/// Logs the info.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="paramList">The param list.</param>
public static void LogInfo(string message, params object[] paramList)
{
LogEntry(message, LogSeverity.Info, null, paramList);
}
/// <summary>
/// Logs the debug info.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="paramList">The param list.</param>
public static void LogDebugInfo(string message, params object[] paramList)
{
LogEntry(message, LogSeverity.Debug, null, paramList);
}
/// <summary>
/// Logs the exception.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="ex">The ex.</param>
/// <param name="paramList">The param list.</param>
public static void LogException(string message, Exception ex, params object[] paramList)
{
LogEntry(message, LogSeverity.Error, ex, paramList);
}
/// <summary>
/// Logs the warning.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="paramList">The param list.</param>
public static void LogWarning(string message, params object[] paramList)
{
LogEntry(message, LogSeverity.Warn, null, paramList);
}
/// <summary>
/// Logs the entry.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="level">The level.</param>
/// <param name="exception">The exception.</param>
/// <param name="paramList">The param list.</param>
private static void LogEntry(string message, LogSeverity level, Exception exception, params object[] paramList)
{
if (LoggerInstance == null)
{
return;
}
if (exception == null)
{
LoggerInstance.Log(level, message, paramList);
}
else
{
if (level == LogSeverity.Fatal)
{
LoggerInstance.FatalException(message, exception, paramList);
}
else
{
LoggerInstance.ErrorException(message, exception, paramList);
}
}
}
}
}

View File

@@ -187,7 +187,6 @@
<Compile Include="Serialization\JsonSerializer.cs" />
<Compile Include="Kernel\BaseKernel.cs" />
<Compile Include="Kernel\KernelContext.cs" />
<Compile Include="Logging\Logger.cs" />
<Compile Include="Net\Handlers\BaseHandler.cs" />
<Compile Include="Net\Handlers\BaseSerializationHandler.cs" />
<Compile Include="Net\HttpServer.cs" />

View File

@@ -189,7 +189,7 @@ namespace MediaBrowser.Common.Plugins
get
{
// Lazy load
LazyInitializer.EnsureInitialized(ref _configuration, ref _configurationInitialized, ref _configurationSyncLock, () => XmlSerializer.GetXmlConfiguration(ConfigurationType, ConfigurationFilePath) as TConfigurationType);
LazyInitializer.EnsureInitialized(ref _configuration, ref _configurationInitialized, ref _configurationSyncLock, () => XmlSerializer.GetXmlConfiguration(ConfigurationType, ConfigurationFilePath, Logger) as TConfigurationType);
return _configuration;
}
protected set
@@ -274,15 +274,21 @@ namespace MediaBrowser.Common.Plugins
/// Starts the plugin.
/// </summary>
/// <param name="kernel">The kernel.</param>
/// <param name="logger">The logger.</param>
/// <exception cref="System.ArgumentNullException">kernel</exception>
public void Initialize(IKernel kernel)
public void Initialize(IKernel kernel, ILogger logger)
{
if (kernel == null)
{
throw new ArgumentNullException("kernel");
}
Logger = LogManager.GetLogger(Name);
if (logger == null)
{
throw new ArgumentNullException("logger");
}
Logger = logger;
Kernel = kernel;

View File

@@ -107,8 +107,9 @@ namespace MediaBrowser.Common.Plugins
/// Starts the plugin.
/// </summary>
/// <param name="kernel">The kernel.</param>
/// <param name="logger">The logger.</param>
/// <exception cref="System.ArgumentNullException">kernel</exception>
void Initialize(IKernel kernel);
void Initialize(IKernel kernel, ILogger logger);
/// <summary>
/// Disposes the plugins. Undos all actions performed during Init.

View File

@@ -3,6 +3,7 @@ using System;
using System.IO;
using System.Linq;
using System.Xml;
using MediaBrowser.Model.Logging;
namespace MediaBrowser.Common.Serialization
{
@@ -157,10 +158,11 @@ namespace MediaBrowser.Common.Serialization
/// </summary>
/// <param name="type">The type.</param>
/// <param name="path">The path.</param>
/// <param name="logger">The logger.</param>
/// <returns>System.Object.</returns>
public static object GetXmlConfiguration(Type type, string path)
public static object GetXmlConfiguration(Type type, string path, ILogger logger)
{
Logger.LogInfo("Loading {0} at {1}", type.Name, path);
logger.Info("Loading {0} at {1}", type.Name, path);
object configuration;
@@ -184,7 +186,7 @@ namespace MediaBrowser.Common.Serialization
// If the file didn't exist before, or if something has changed, re-save
if (buffer == null || !buffer.SequenceEqual(newBytes))
{
Logger.LogInfo("Saving {0} to {1}", type.Name, path);
logger.Info("Saving {0} to {1}", type.Name, path);
// Save it after load in case we got new items
File.WriteAllBytes(path, newBytes);
@@ -200,11 +202,12 @@ namespace MediaBrowser.Common.Serialization
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="path">The path.</param>
/// <param name="logger">The logger.</param>
/// <returns>``0.</returns>
public static T GetXmlConfiguration<T>(string path)
public static T GetXmlConfiguration<T>(string path, ILogger logger)
where T : class
{
return GetXmlConfiguration(typeof(T), path) as T;
return GetXmlConfiguration(typeof(T), path, logger) as T;
}
}
}