add console logging during startup

This commit is contained in:
Luke Pulverenti
2014-01-08 23:44:51 -05:00
parent dcc5f9ebab
commit 247a40fa61
12 changed files with 79 additions and 50 deletions

View File

@@ -32,7 +32,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
private string DefaultRedirectPath { get; set; }
private readonly ILogger _logger;
public string UrlPrefix { get; private set; }
public IEnumerable<string> UrlPrefixes { get; private set; }
private readonly List<IRestfulService> _restServices = new List<IRestfulService>();
@@ -66,7 +66,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
_containerAdapter = new ContainerAdapter(applicationHost);
for (var i = 0; i < 2; i++)
for (var i = 0; i < 1; i++)
{
_autoResetEvents.Add(new AutoResetEvent(false));
}
@@ -145,20 +145,14 @@ namespace MediaBrowser.Server.Implementations.HttpServer
public override ServiceStackHost Start(string listeningAtUrlBase)
{
StartListener(listeningAtUrlBase);
StartListener();
return this;
}
/// <summary>
/// Starts the Web Service
/// </summary>
/// <param name="listeningAtUrlBase">
/// A Uri that acts as the base that the server is listening on.
/// Format should be: http://127.0.0.1:8080/ or http://127.0.0.1:8080/somevirtual/
/// Note: the trailing slash is required! For more info see the
/// HttpListener.Prefixes property on MSDN.
/// </param>
protected void StartListener(string listeningAtUrlBase)
private void StartListener()
{
// *** Already running - just leave it in place
if (IsStarted)
@@ -167,14 +161,13 @@ namespace MediaBrowser.Server.Implementations.HttpServer
if (Listener == null)
Listener = new HttpListener();
HostContext.Config.HandlerFactoryPath = ListenerRequest.GetHandlerPathIfAny(listeningAtUrlBase);
HostContext.Config.HandlerFactoryPath = ListenerRequest.GetHandlerPathIfAny(UrlPrefixes.First());
UrlPrefix = listeningAtUrlBase;
Listener.Prefixes.Add(listeningAtUrlBase);
_logger.Info("Adding HttpListener Prefixes");
Listener.Prefixes.Add(listeningAtUrlBase);
foreach (var prefix in UrlPrefixes)
{
_logger.Info("Adding HttpListener prefix " + prefix);
Listener.Prefixes.Add(prefix);
}
IsStarted = true;
_logger.Info("Starting HttpListner");
@@ -419,7 +412,10 @@ namespace MediaBrowser.Server.Implementations.HttpServer
{
if (Listener != null)
{
Listener.Prefixes.Remove(UrlPrefix);
foreach (var prefix in UrlPrefixes)
{
Listener.Prefixes.Remove(prefix);
}
Listener.Close();
}
@@ -516,9 +512,10 @@ namespace MediaBrowser.Server.Implementations.HttpServer
GC.SuppressFinalize(this);
}
public void StartServer(string urlPrefix)
public void StartServer(IEnumerable<string> urlPrefixes)
{
Start(urlPrefix);
UrlPrefixes = urlPrefixes.ToList();
Start(UrlPrefixes.First());
}
public bool SupportsWebSockets

View File

@@ -124,9 +124,9 @@ namespace MediaBrowser.Server.Implementations.ServerManager
/// <summary>
/// Starts this instance.
/// </summary>
public void Start(string urlPrefix, bool enableHttpLogging)
public void Start(IEnumerable<string> urlPrefixes, bool enableHttpLogging)
{
ReloadHttpServer(urlPrefix, enableHttpLogging);
ReloadHttpServer(urlPrefixes, enableHttpLogging);
}
public void StartWebSocketServer()
@@ -153,14 +153,8 @@ namespace MediaBrowser.Server.Implementations.ServerManager
/// <summary>
/// Restarts the Http Server, or starts it if not currently running
/// </summary>
private void ReloadHttpServer(string urlPrefix, bool enableHttpLogging)
private void ReloadHttpServer(IEnumerable<string> urlPrefixes, bool enableHttpLogging)
{
// Only reload if the port has changed, so that we don't disconnect any active users
if (HttpServer != null && HttpServer.UrlPrefix.Equals(urlPrefix, StringComparison.OrdinalIgnoreCase))
{
return;
}
DisposeHttpServer();
_logger.Info("Loading Http Server");
@@ -169,7 +163,7 @@ namespace MediaBrowser.Server.Implementations.ServerManager
{
HttpServer = _applicationHost.Resolve<IHttpServer>();
HttpServer.EnableHttpRequestLogging = enableHttpLogging;
HttpServer.StartServer(urlPrefix);
HttpServer.StartServer(urlPrefixes);
}
catch (SocketException ex)
{