/// <summary> /// Attempts to write to a specified logfile. No error is logged if it cannot /// </summary> /// <remarks>It checks to make sure the logfile isn't disposed, and then to make sure the logfile is open in a valid instance</remarks> /// <param name="message">The message to write</param> /// <param name="logfile">The logfile to write to</param> /// <param name="logLevel">The level of severity of the message. If not Application log, this parameter is ignored</param> public static void TryWriteToLog(string message, Logfiles logfile, LogLevel logLevel) { if (!IsLogDisposed(logfile) && IsLogOpen(logfile)) { WriteToLog(message, logfile, logLevel); } }
private void CloseLog(Logfiles logfile) { if (!Logging.IsLogDisposed(logfile)) { Logging.DisposeLogging(logfile); } }
/// <summary> /// Dispose of the application logging subsystem /// </summary> /// <param name="logfile">The logfile to dispose</param> public static void DisposeLogging(Logfiles logfile) { switch (logfile) { case Logfiles.Application: ApplicationLogfile.Dispose(); ApplicationLogfile = null; break; case Logfiles.Installer: InstallLogfile.Dispose(); InstallLogfile = null; break; case Logfiles.Uninstaller: UninstallLogfile.Dispose(); UninstallLogfile = null; break; case Logfiles.Editor: EditorLogfile.Dispose(); EditorLogfile = null; break; case Logfiles.PatchDesigner: PatcherLogfile.Dispose(); PatcherLogfile = null; break; case Logfiles.Updater: UpdaterLogfile.Dispose(); UpdaterLogfile = null; break; } }
/// <summary> /// Create an instance of the DatabaseAutomationRunner window /// </summary> public DatabaseAutomationRunner(ModpackSettings modpackSettings, Logfiles logfile) : base(modpackSettings, logfile) { InitializeComponent(); DownloadProgressChanged = WebClient_DownloadProgressChanged; DownloadDataCompleted = WebClient_DownloadDataComplted; DownloadFileCompleted = WebClient_TransferFileCompleted; UploadFileCompleted = WebClient_UploadFileCompleted; UploadProgressChanged = WebClient_UploadProgressChanged; RelhaxProgressChanged = RelhaxProgressReport_ProgressChanged; ProgressChanged = GenericProgressChanged; Settings = AutomationSettings; //https://stackoverflow.com/questions/7712137/array-containing-methods settingsMethods = new Action[] { () => OpenLogWindowOnStartupSetting_Click(null, null), () => BigmodsUsernameSetting_TextChanged(null, null), () => BigmodsPasswordSetting_TextChanged(null, null), () => DumpParsedMacrosPerSequenceRunSetting_Click(null, null), () => DumpEnvironmentVariablesAtSequenceStartSetting_Click(null, null), () => SuppressDebugMessagesSetting_Click(null, null), () => AutomamtionDatabaseSelectedBranchSetting_TextChanged(null, null), () => SelectDBSaveLocationSetting_TextChanged(null, null), () => UseLocalRunnerDatabaseSetting_Click(null, null), () => LocalRunnerDatabaseRootSetting_TextChanged(null, null), () => SelectWoTInstallLocationSetting_TextChanged(null, null) }; }
/// <summary> /// Checks if the logfile is instanced and can be written to using the CanWrite property /// </summary> /// <param name="file">The logfile to check</param> /// <returns>True if the logfile is open and available to be written to</returns> public static bool IsLogOpen(Logfiles file) { switch (file) { case Logfiles.Installer: if (InstallLogfile == null) { return(false); } return(InstallLogfile.CanWrite); case Logfiles.Uninstaller: if (UninstallLogfile == null) { return(false); } return(UninstallLogfile.CanWrite); case Logfiles.Editor: if (EditorLogfile == null) { return(false); } return(EditorLogfile.CanWrite); case Logfiles.PatchDesigner: if (PatcherLogfile == null) { return(false); } return(PatcherLogfile.CanWrite); case Logfiles.Updater: if (UpdaterLogfile == null) { return(false); } return(UpdaterLogfile.CanWrite); case Logfiles.Application: default: if (ApplicationLogfile == null) { return(false); } return(ApplicationLogfile.CanWrite); } }
/// <summary> /// Writes the ApplicationlogStartStop constant to the logfile /// </summary> /// <param name="logfile">The logfile to write the header on</param> public static void WriteHeader(Logfiles logfile) { switch (logfile) { case Logfiles.Application: ApplicationLogfile.Write(ApplicationlogStartStop); break; case Logfiles.Editor: EditorLogfile.Write(ApplicationlogStartStop); break; case Logfiles.PatchDesigner: PatcherLogfile.Write(ApplicationlogStartStop); break; case Logfiles.Updater: UpdaterLogfile.Write(ApplicationlogStartStop); break; } }
/// <summary> /// Checks if the logfile is disposed /// </summary> /// <param name="file">The logfile to check</param> /// <returns>True if the logfile object is null</returns> public static bool IsLogDisposed(Logfiles file) { switch (file) { case Logfiles.Installer: return(InstallLogfile == null ? true : false); case Logfiles.Uninstaller: return(UninstallLogfile == null ? true : false); case Logfiles.Editor: return(EditorLogfile == null ? true : false); case Logfiles.PatchDesigner: return(PatcherLogfile == null ? true : false); case Logfiles.Updater: return(UpdaterLogfile == null ? true : false); case Logfiles.Application: default: return(ApplicationLogfile == null ? true : false); } }
/// <summary> /// Writes a message to a logfile instance, if it exists /// </summary> /// <param name="messageFormat">The formatted string to be passed into the string.Format() method</param> /// <param name="logfile">The logfile to write to</param> /// <param name="level">The severity level of the message. Will be written as part of the format</param> /// <param name="args">The arguments to be passed into the string.Format() method</param> public static void WriteToLog(string messageFormat, Logfiles logfile, LogLevel level, params object[] args) { WriteToLog(string.Format(messageFormat, args), logfile, level); }
/// <summary> /// Writes a message to a logfile instance, if it exists /// </summary> /// <param name="message">The message to write</param> /// <param name="logfiles">The logfile to write to</param> /// <param name="logLevel">The level of severity of the message. If not Application log, this parameter is ignored</param> public static void WriteToLog(string message, Logfiles logfiles, LogLevel logLevel) { Logfile fileToWriteTo = null; switch (logfiles) { case Logfiles.Application: fileToWriteTo = ApplicationLogfile; break; case Logfiles.Updater: fileToWriteTo = UpdaterLogfile; break; case Logfiles.Editor: fileToWriteTo = EditorLogfile; break; case Logfiles.PatchDesigner: fileToWriteTo = PatcherLogfile; break; case Logfiles.Installer: fileToWriteTo = InstallLogfile; break; case Logfiles.Uninstaller: fileToWriteTo = UninstallLogfile; break; } //check if the application logfile is null and the application is now in a new mode if (fileToWriteTo == null && CommandLineSettings.ApplicationMode != ApplicationMode.Default) { switch (CommandLineSettings.ApplicationMode) { case ApplicationMode.Editor: fileToWriteTo = EditorLogfile; break; case ApplicationMode.PatchDesigner: fileToWriteTo = PatcherLogfile; break; case ApplicationMode.Updater: fileToWriteTo = UpdaterLogfile; break; } } //check if logfile is null else if (fileToWriteTo == null) { //check if it's the application logfile if (fileToWriteTo == ApplicationLogfile) { if (!FailedToWriteToLogWindowShown) { MessageBox.Show("Failed to write to application log: instance is null!"); FailedToWriteToLogWindowShown = true; } } else { WriteToLog(string.Format("Tried to write to null log instance: {0}", logfiles.ToString()), Logfiles.Application, LogLevel.Error); } return; } if (logfiles == Logfiles.PatchDesigner || logfiles == Logfiles.Editor) { string temp = fileToWriteTo.Write(message, logLevel); OnLoggingUIThreadReport?.Invoke(temp); } else { fileToWriteTo.Write(message, logLevel); } }
#pragma warning restore CA1009 /// <summary> /// Initialize the logging system for the application /// </summary> /// <param name="logfile">The log file to initialize</param> /// <param name="logfilePath">The custom path of where to initialize the file</param> /// <returns>True if successful initialization, false otherwise</returns> public static bool Init(Logfiles logfile, string logfilePath = null) { Logfile fileToWriteTo = null; //assign it here first to make sure it's null switch (logfile) { case Logfiles.Application: fileToWriteTo = ApplicationLogfile; logfilePath = ApplicationLogFilename; break; case Logfiles.Installer: fileToWriteTo = InstallLogfile; break; case Logfiles.Uninstaller: fileToWriteTo = UninstallLogfile; break; case Logfiles.Editor: fileToWriteTo = EditorLogfile; logfilePath = ApplicationEditorLogFilename; break; case Logfiles.PatchDesigner: fileToWriteTo = PatcherLogfile; logfilePath = ApplicationPatchDesignerLogFilename; break; case Logfiles.Updater: fileToWriteTo = UpdaterLogfile; logfilePath = ApplicationUpdaterLogFilename; break; } if (fileToWriteTo != null) { throw new BadMemeException("only do this once jackass"); } #pragma warning disable IDE0068 // Use recommended dispose pattern fileToWriteTo = new Logfile(logfilePath, ApplicationLogfileTimestamp); #pragma warning restore IDE0068 // Use recommended dispose pattern //now that it's newed, the reference needs to be reverse assigned switch (logfile) { case Logfiles.Application: ApplicationLogfile = fileToWriteTo; break; case Logfiles.Installer: InstallLogfile = fileToWriteTo; break; case Logfiles.Uninstaller: UninstallLogfile = fileToWriteTo; break; case Logfiles.Editor: EditorLogfile = fileToWriteTo; break; case Logfiles.PatchDesigner: PatcherLogfile = fileToWriteTo; break; case Logfiles.Updater: UpdaterLogfile = fileToWriteTo; break; } if (!fileToWriteTo.Init()) { MessageBox.Show(string.Format("Failed to initialize logfile {0}, check file permissions", logfilePath)); return(false); } return(true); }
/// <summary> /// Creates an instance of the RelhaxCustomFeatureWindow class /// </summary> public RelhaxCustomFeatureWindow(ModpackSettings modpackSettings, Logfiles logfile) : base(modpackSettings) { Logfile = logfile; }
public RelhaxFeatureWindowWithChanges(ModpackSettings modpackSettings, Logfiles logfile) : base(modpackSettings, logfile) { }
/// <summary> /// Create an instance of the PatchDesigner window /// </summary> public PatchDesigner(ModpackSettings modpackSettings, Logfiles logfile) : base(modpackSettings, logfile) { InitializeComponent(); Settings = PatchSettings; }