private static bool Run(string[] args) { Console.OutputEncoding = Encoding.UTF8; var ctx = new Context(); ctx.Options = CliParser.Parse(args); if (ctx.Options == null) { return(false); } StreamWriter logWriter = null; ResultLogger resultLogger = null; try { using (var logger = new ProgressBar()) { ctx.Logger = logger; ctx.FsClient = new FileSystemClient(new StopWatchTimeSpanGenerator()); if (ctx.Options.AccessLog != null) { logWriter = new StreamWriter(ctx.Options.AccessLog); var accessLog = new TextWriterAccessLog(logWriter); ctx.FsClient.SetAccessLogTarget(AccessLogTarget.All); ctx.FsClient.SetGlobalAccessLogMode(GlobalAccessLogMode.Log); ctx.FsClient.SetAccessLogObject(accessLog); } if (ctx.Options.ResultLog != null) { resultLogger = new ResultLogger(new StreamWriter(ctx.Options.ResultLog), printStackTrace: true, printSourceInfo: true, combineRepeats: true); Result.SetLogger(resultLogger); } OpenKeyset(ctx); if (ctx.Options.RunCustom) { CustomTask(ctx); return(true); } RunTask(ctx); } } finally { logWriter?.Dispose(); if (resultLogger != null) { Result.SetLogger(null); resultLogger.Dispose(); } } return(true); }
private static bool Run(string[] args) { Console.OutputEncoding = Encoding.UTF8; var ctx = new Context(); ctx.Options = CliParser.Parse(args); if (ctx.Options == null) { return(false); } StreamWriter logWriter = null; ResultLogger resultLogger = null; LogObserverHolder logObserver = null; try { using (var logger = new ProgressBar()) { ctx.Logger = logger; OpenKeySet(ctx); InitializeHorizon(ctx); if (ctx.Options.AccessLog != null) { logWriter = new StreamWriter(ctx.Options.AccessLog); logObserver = new LogObserverHolder(); // ReSharper disable once AccessToDisposedClosure // References to logWriter should be gone by the time it's disposed ctx.Horizon.Diag.InitializeLogObserverHolder(ref logObserver, (in LogMetaData data, in LogBody body, object arguments) => logWriter.Write(body.Message.ToString()), null); ctx.Horizon.Diag.RegisterLogObserver(logObserver); ctx.Horizon.Fs.SetLocalSystemAccessLogForDebug(true); ctx.Horizon.Fs.SetGlobalAccessLogMode(GlobalAccessLogMode.Log).ThrowIfFailure(); } if (ctx.Options.ResultLog != null) { resultLogger = new ResultLogger(new StreamWriter(ctx.Options.ResultLog), printStackTrace: true, printSourceInfo: true, combineRepeats: true); Result.SetLogger(resultLogger); } if (ctx.Options.RunCustom) { CustomTask(ctx); return(true); } RunTask(ctx); } } finally { if (logObserver != null) { ctx.Horizon.Diag.UnregisterLogObserver(logObserver); } logWriter?.Dispose(); if (resultLogger != null) { Result.SetLogger(null); resultLogger.Dispose(); } } return(true); }