public IDisposable RelayLogging(string logName, bool backupOldFile = true) { var logFileName = logName + ".log"; string logFileFullName; var disposable = this.AsDisposable(() => { ClearSetting(); }); logFileFullName = Path.Combine(this.RootPath, logFileName); if (backupOldFile) { if (File.Exists(logFileFullName)) { try { var fileInfo = new FileInfo(logFileFullName); var backupFileName = Path.Combine(fileInfo.DirectoryName, string.Format("{0} {1}", DateTime.Now.ToSortableDateTimeText(), fileInfo.Name)); File.Copy(logFileFullName, backupFileName); File.Delete(logFileFullName); } catch (Exception ex) { } } } InterprocessVariables.SetVariable(this.RootPath, this.Domain, "RelayLogFileName", logFileName); return(disposable); }
private void ClearSetting() { InterprocessVariables.SetVariable(this.RootPath, this.Domain, "RelayLogFileName", string.Empty); }