From 76f067f86778c29fbfb3716a72bc858cfdd73fd8 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Thu, 21 Feb 2013 16:06:23 -0500 Subject: extracted more logging dependancies --- MediaBrowser.Common/Net/AlchemyWebSocket.cs | 10 ++++++---- MediaBrowser.Common/Net/HttpServer.cs | 26 ++++++++++++++++++-------- MediaBrowser.Common/Net/NativeWebSocket.cs | 18 ++++++++++++------ MediaBrowser.Common/Net/WebSocketConnection.cs | 15 ++++++++++----- 4 files changed, 46 insertions(+), 23 deletions(-) (limited to 'MediaBrowser.Common/Net') diff --git a/MediaBrowser.Common/Net/AlchemyWebSocket.cs b/MediaBrowser.Common/Net/AlchemyWebSocket.cs index 1971990db9..5a5103f74c 100644 --- a/MediaBrowser.Common/Net/AlchemyWebSocket.cs +++ b/MediaBrowser.Common/Net/AlchemyWebSocket.cs @@ -17,7 +17,7 @@ namespace MediaBrowser.Common.Net /// /// The logger /// - private static ILogger Logger = LogManager.GetLogger("AlchemyWebSocket"); + private readonly ILogger _logger; /// /// Gets or sets the web socket. @@ -29,20 +29,22 @@ namespace MediaBrowser.Common.Net /// Initializes a new instance of the class. /// /// The context. + /// The logger. /// context - public AlchemyWebSocket(UserContext context) + public AlchemyWebSocket(UserContext context, ILogger logger) { if (context == null) { throw new ArgumentNullException("context"); } + _logger = logger; UserContext = context; context.SetOnDisconnect(OnDisconnected); context.SetOnReceive(OnReceive); - Logger.Info("Client connected from {0}", context.ClientAddress); + _logger.Info("Client connected from {0}", context.ClientAddress); } /// @@ -87,7 +89,7 @@ namespace MediaBrowser.Common.Net } catch (Exception ex) { - Logger.ErrorException("Error processing web socket message", ex); + _logger.ErrorException("Error processing web socket message", ex); } } } diff --git a/MediaBrowser.Common/Net/HttpServer.cs b/MediaBrowser.Common/Net/HttpServer.cs index c09153064e..7183b63c0f 100644 --- a/MediaBrowser.Common/Net/HttpServer.cs +++ b/MediaBrowser.Common/Net/HttpServer.cs @@ -32,7 +32,7 @@ namespace MediaBrowser.Common.Net /// /// The logger /// - private static ILogger Logger = Logging.LogManager.GetLogger("HttpServer"); + private readonly ILogger _logger; /// /// Gets the URL prefix. @@ -69,17 +69,27 @@ namespace MediaBrowser.Common.Net /// The URL. /// Name of the product. /// The kernel. + /// The logger. /// The default redirectpath. /// urlPrefix - public HttpServer(string urlPrefix, string serverName, IKernel kernel, string defaultRedirectpath = null) + public HttpServer(string urlPrefix, string serverName, IKernel kernel, ILogger logger, string defaultRedirectpath = null) : base() { if (string.IsNullOrEmpty(urlPrefix)) { throw new ArgumentNullException("urlPrefix"); } + if (kernel == null) + { + throw new ArgumentNullException("kernel"); + } + if (logger == null) + { + throw new ArgumentNullException("logger"); + } DefaultRedirectPath = defaultRedirectpath; + _logger = logger; EndpointHostConfig.Instance.ServiceStackHandlerFactoryPath = null; EndpointHostConfig.Instance.MetadataRedirectPath = "metadata"; @@ -274,12 +284,12 @@ namespace MediaBrowser.Common.Net if (WebSocketConnected != null) { - WebSocketConnected(this, new WebSocketConnectEventArgs { WebSocket = new NativeWebSocket(webSocketContext.WebSocket), Endpoint = ctx.Request.RemoteEndPoint }); + WebSocketConnected(this, new WebSocketConnectEventArgs { WebSocket = new NativeWebSocket(webSocketContext.WebSocket, _logger), Endpoint = ctx.Request.RemoteEndPoint }); } } catch (Exception ex) { - Logger.ErrorException("AcceptWebSocketAsync error", ex); + _logger.ErrorException("AcceptWebSocketAsync error", ex); ctx.Response.StatusCode = 500; ctx.Response.Close(); @@ -301,7 +311,7 @@ namespace MediaBrowser.Common.Net if (Kernel.Configuration.EnableHttpLevelLogging) { - Logger.LogMultiline(type + " request received from " + ctx.Request.RemoteEndPoint, LogSeverity.Debug, log); + _logger.LogMultiline(type + " request received from " + ctx.Request.RemoteEndPoint, LogSeverity.Debug, log); } } @@ -313,7 +323,7 @@ namespace MediaBrowser.Common.Net /// The status code. private void HandleException(HttpListenerResponse response, Exception ex, int statusCode) { - Logger.ErrorException("Error processing request", ex); + _logger.ErrorException("Error processing request", ex); response.StatusCode = statusCode; @@ -352,7 +362,7 @@ namespace MediaBrowser.Common.Net } catch (Exception errorEx) { - Logger.ErrorException("Error processing failed request", errorEx); + _logger.ErrorException("Error processing failed request", errorEx); } } @@ -408,7 +418,7 @@ namespace MediaBrowser.Common.Net if (Kernel.Configuration.EnableHttpLevelLogging) { - Logger.LogMultiline(msg, LogSeverity.Debug, log); + _logger.LogMultiline(msg, LogSeverity.Debug, log); } } diff --git a/MediaBrowser.Common/Net/NativeWebSocket.cs b/MediaBrowser.Common/Net/NativeWebSocket.cs index d57deca54e..23f3d4be34 100644 --- a/MediaBrowser.Common/Net/NativeWebSocket.cs +++ b/MediaBrowser.Common/Net/NativeWebSocket.cs @@ -1,5 +1,4 @@ -using MediaBrowser.Common.Logging; -using MediaBrowser.Common.Serialization; +using MediaBrowser.Common.Serialization; using MediaBrowser.Model.Logging; using System; using System.IO; @@ -17,7 +16,7 @@ namespace MediaBrowser.Common.Net /// /// The logger /// - private static ILogger Logger = LogManager.GetLogger("NativeWebSocket"); + private readonly ILogger _logger; /// /// Gets or sets the web socket. @@ -29,14 +28,21 @@ namespace MediaBrowser.Common.Net /// Initializes a new instance of the class. /// /// The socket. + /// The logger. /// socket - public NativeWebSocket(WebSocket socket) + public NativeWebSocket(WebSocket socket, ILogger logger) { if (socket == null) { throw new ArgumentNullException("socket"); } + if (logger == null) + { + throw new ArgumentNullException("logger"); + } + + _logger = logger; WebSocket = socket; Receive(); @@ -66,7 +72,7 @@ namespace MediaBrowser.Common.Net } catch (WebSocketException ex) { - Logger.ErrorException("Error reveiving web socket message", ex); + _logger.ErrorException("Error reveiving web socket message", ex); break; } @@ -83,7 +89,7 @@ namespace MediaBrowser.Common.Net } catch (Exception ex) { - Logger.ErrorException("Error processing web socket message", ex); + _logger.ErrorException("Error processing web socket message", ex); } } } diff --git a/MediaBrowser.Common/Net/WebSocketConnection.cs b/MediaBrowser.Common/Net/WebSocketConnection.cs index ca12d07be8..24b8e2a9fd 100644 --- a/MediaBrowser.Common/Net/WebSocketConnection.cs +++ b/MediaBrowser.Common/Net/WebSocketConnection.cs @@ -37,7 +37,7 @@ namespace MediaBrowser.Common.Net /// /// The logger /// - private static readonly ILogger Logger = LogManager.GetLogger("WebSocketConnection"); + private readonly ILogger _logger; /// /// Initializes a new instance of the class. @@ -46,7 +46,7 @@ namespace MediaBrowser.Common.Net /// The remote end point. /// The receive action. /// socket - public WebSocketConnection(IWebSocket socket, EndPoint remoteEndPoint, Action receiveAction) + public WebSocketConnection(IWebSocket socket, EndPoint remoteEndPoint, Action receiveAction, ILogger logger) { if (socket == null) { @@ -60,10 +60,15 @@ namespace MediaBrowser.Common.Net { throw new ArgumentNullException("receiveAction"); } + if (logger == null) + { + throw new ArgumentNullException("logger"); + } _socket = socket; _socket.OnReceiveDelegate = info => OnReceive(info, receiveAction); RemoteEndPoint = remoteEndPoint; + _logger = logger; } /// @@ -81,7 +86,7 @@ namespace MediaBrowser.Common.Net } catch (Exception ex) { - Logger.ErrorException("Error processing web socket message", ex); + _logger.ErrorException("Error processing web socket message", ex); } } @@ -148,13 +153,13 @@ namespace MediaBrowser.Common.Net } catch (OperationCanceledException) { - Logger.Info("WebSocket message to {0} was cancelled", RemoteEndPoint); + _logger.Info("WebSocket message to {0} was cancelled", RemoteEndPoint); throw; } catch (Exception ex) { - Logger.ErrorException("Error sending WebSocket message {0}", ex, RemoteEndPoint); + _logger.ErrorException("Error sending WebSocket message {0}", ex, RemoteEndPoint); throw; } -- cgit v1.2.3