Add command line option to specify the logging directory (#336)

Two changes in this PR:
* Add a --log-dir command line parameter and fix command line parsing
* Fix command line parsing where arguments with parameter were parsed incorrectly
This commit is contained in:
Brian O'Neill
2017-05-10 08:55:46 -07:00
committed by GitHub
parent 2e9843cec1
commit 7625c8d83d
6 changed files with 124 additions and 55 deletions

View File

@@ -6,6 +6,7 @@ using Microsoft.SqlTools.ServiceLayer.Hosting;
using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Microsoft.SqlTools.ServiceLayer.Utility;
using Microsoft.SqlTools.Utility;
using System.IO;
namespace Microsoft.SqlTools.ServiceLayer
{
@@ -19,26 +20,39 @@ namespace Microsoft.SqlTools.ServiceLayer
/// </summary>
internal static void Main(string[] args)
{
// read command-line arguments
CommandOptions commandOptions = new CommandOptions(args);
if (commandOptions.ShouldExit)
try
{
return;
// read command-line arguments
CommandOptions commandOptions = new CommandOptions(args);
if (commandOptions.ShouldExit)
{
return;
}
string logFilePath = "sqltools";
if (!string.IsNullOrWhiteSpace(commandOptions.LoggingDirectory))
{
logFilePath = Path.Combine(commandOptions.LoggingDirectory, logFilePath);
}
// turn on Verbose logging during early development
// we need to switch to Normal when preparing for public preview
Logger.Initialize(logFilePath: logFilePath, minimumLogLevel: LogLevel.Verbose, isEnabled: commandOptions.EnableLogging);
Logger.Write(LogLevel.Normal, "Starting SQL Tools Service Host");
// set up the host details and profile paths
var hostDetails = new HostDetails(version: new Version(1, 0));
SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails);
ServiceHost serviceHost = HostLoader.CreateAndStartServiceHost(sqlToolsContext);
serviceHost.WaitForExit();
}
catch (Exception e)
{
Logger.Write(LogLevel.Error, string.Format("An unhandled exception occurred: {0}", e));
Environment.Exit(1);
}
// turn on Verbose logging during early development
// we need to switch to Normal when preparing for public preview
Logger.Initialize(minimumLogLevel: LogLevel.Verbose, isEnabled: commandOptions.EnableLogging);
Logger.Write(LogLevel.Normal, "Starting SQL Tools Service Host");
// set up the host details and profile paths
var hostDetails = new HostDetails(version: new Version(1, 0));
SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails);
ServiceHost serviceHost = HostLoader.CreateAndStartServiceHost(sqlToolsContext);
serviceHost.WaitForExit();
}
}
}