diff --git a/src/DynamoCLI/Program.cs b/src/DynamoCLI/Program.cs index 4d11087f13f..59a2c9e11bd 100644 --- a/src/DynamoCLI/Program.cs +++ b/src/DynamoCLI/Program.cs @@ -86,9 +86,9 @@ private static void RunKeepAlive(StartupUtils.CommandLineArguments cmdLineArgs) Console.WriteLine("Press Enter to shutdown..."); } } - catch + catch(Exception ex) { - Console.WriteLine("Server is shutting down due to an error"); + Console.WriteLine("Server is shutting down due to an error : " + ex.ToString()); } } diff --git a/src/DynamoCore/Logging/DynamoLogger.cs b/src/DynamoCore/Logging/DynamoLogger.cs index 8744f78dc7f..b9f04100bc2 100644 --- a/src/DynamoCore/Logging/DynamoLogger.cs +++ b/src/DynamoCore/Logging/DynamoLogger.cs @@ -77,6 +77,7 @@ public class DynamoLogger: NotificationObject, ILogger, IDisposable private bool _isDisposed; private readonly bool testMode; private readonly bool cliMode; + private readonly bool serviceMode; private TextWriter FileWriter { get; set; } private StringBuilder ConsoleWriter { get; set; } @@ -159,7 +160,7 @@ public IEnumerable StartupNotifications /// /// Debug settings /// Directory path where log file will be written - [Obsolete("This will be removed in 3.0, please use DynamoLogger(debugSettings, logDirectory, isTestMode) instead.")] + [Obsolete("This will be removed in 3.0, please use DynamoLogger(debugSettings, logDirectory, isTestMode, isCLIMode, isServiceMode) instead.")] public DynamoLogger(DebugSettings debugSettings, string logDirectory) : this(debugSettings, logDirectory, false) { @@ -172,6 +173,7 @@ public DynamoLogger(DebugSettings debugSettings, string logDirectory) : this(deb /// Debug settings /// Directory path where log file will be written /// Test mode is true or false. + [Obsolete("This will be removed in 3.0, please use DynamoLogger(debugSettings, logDirectory, isTestMode, isCLIMode, isServiceMode) instead.")] public DynamoLogger(DebugSettings debugSettings, string logDirectory, Boolean isTestMode) { lock (guardMutex) @@ -203,6 +205,7 @@ public DynamoLogger(DebugSettings debugSettings, string logDirectory, Boolean is /// Directory path where log file will be written /// Test mode is true or false. /// We want to allow logging when CLI mode is true even if we are in test mode. + [Obsolete("This will be removed in 3.0, please use DynamoLogger(debugSettings, logDirectory, isTestMode, isCLIMode, isServiceMode) instead.")] public DynamoLogger(DebugSettings debugSettings, string logDirectory, Boolean isTestMode, Boolean isCLIMode) :this(debugSettings, logDirectory, isTestMode) { @@ -213,6 +216,42 @@ public DynamoLogger(DebugSettings debugSettings, string logDirectory, Boolean is } } + /// + /// Initializes a new instance of class + /// with specified debug settings and directory where to write logs + /// + /// Debug settings + /// Directory path where log file will be written + /// Test mode is true or false. + /// We want to allow logging when CLI mode is true even if we are in test mode. + /// We want restrict logging in service mode to console only due to lambda limitations. + /// TODO(DYN-5757): Review usage of isTestMode,isTestMode,isServiceMode across Dynamo and see how we can consildate all these flags. + public DynamoLogger(DebugSettings debugSettings, string logDirectory, Boolean isTestMode, Boolean isCLIMode, Boolean isServiceMode) + : this(debugSettings, logDirectory, isTestMode) + { + lock (guardMutex) + { + this.debugSettings = debugSettings; + _isDisposed = false; + + WarningLevel = WarningLevel.Mild; + Warning = ""; + + notifications = new List(); + + testMode = isTestMode; + cliMode = isCLIMode; + serviceMode = isServiceMode; + + if (!testMode && !isServiceMode) + { + StartLoggingToConsoleAndFile(logDirectory); + } + + XmlDocumentationExtensions.LogToConsole += Log; + } + } + /// /// Logs the specified message. /// @@ -244,6 +283,12 @@ private void Log(string message, LogLevel level, bool reportModification) return; } + if (serviceMode && (level == LogLevel.Console || level == LogLevel.File)) + { + ConsoleWriter.AppendLine("LogLevel switched to ConsoleOnly in service mode"); + level = LogLevel.ConsoleOnly; + } + switch (level) { //write to the console only @@ -444,7 +489,8 @@ private void StartLoggingToConsoleAndFile(string logDirectory) { lock (this.guardMutex) { - if (FileWriter != null && ConsoleWriter != null) + if (serviceMode || + (FileWriter != null && ConsoleWriter != null)) { return; } diff --git a/src/DynamoCore/Models/DynamoModel.cs b/src/DynamoCore/Models/DynamoModel.cs index 41ac3b4da02..882eb6b71ec 100644 --- a/src/DynamoCore/Models/DynamoModel.cs +++ b/src/DynamoCore/Models/DynamoModel.cs @@ -648,7 +648,7 @@ protected DynamoModel(IStartConfiguration config) IsHeadless = config.IsHeadless; DebugSettings = new DebugSettings(); - Logger = new DynamoLogger(DebugSettings, pathManager.LogDirectory, IsTestMode, CLIMode); + Logger = new DynamoLogger(DebugSettings, pathManager.LogDirectory, IsTestMode, CLIMode, IsServiceMode); if (!IsServiceMode) { @@ -2439,6 +2439,12 @@ private void RegisterHomeWorkspace(HomeWorkspaceModel newWorkspace) /// protected void SaveBackupFiles(object state) { + //No backup files in ServiceMode due to Lambda restrictions + if (IsServiceMode) + { + return; + } + OnRequestDispatcherBeginInvoke(() => { // tempDict stores the list of backup files and their corresponding workspaces IDs