public override void Log(string message, Exception ex, TraceLevel traceLevel, params object[] formatArgs) { switch (traceLevel) { case TraceLevel.Error: _psHostUserInterface.WriteErrorLine(string.Format(message, formatArgs)); break; case TraceLevel.Info: _psHostUserInterface.WriteLine(string.Format(message, formatArgs)); break; case TraceLevel.Verbose: _psHostUserInterface.WriteVerboseLine(string.Format(message, formatArgs)); break; case TraceLevel.Warning: _psHostUserInterface.WriteWarningLine(string.Format(message, formatArgs)); break; default: _psHostUserInterface.WriteLine(string.Format(message, formatArgs)); break; } }
public override void WriteWarningLine(string message) { string[] lines = message.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None); foreach (string line in lines) { string temp = line; SendToSubscribers(s => s.WriteWarning(temp.TrimEnd() + "\r\n")); } if (externalUI != null) { externalUI.WriteWarningLine(message); } }
public static PowerShell WithStreamsOutput(this PowerShell ps, PSHostUserInterface psui) { ps.Streams.Information.DataAdded += (sender, args) => { var data = ((PSDataCollection <InformationRecord>)sender)[args.Index]; psui.WriteInformation(data); }; ps.Streams.Progress.DataAdded += (sender, args) => { var data = ((PSDataCollection <ProgressRecord>)sender)[args.Index]; psui.WriteProgress(data.ActivityId, data); }; ps.Streams.Debug.DataAdded += (sender, args) => { var data = ((PSDataCollection <DebugRecord>)sender)[args.Index]; psui.WriteDebugLine(data.Message); }; ps.Streams.Verbose.DataAdded += (sender, args) => { var data = ((PSDataCollection <VerboseRecord>)sender)[args.Index]; psui.WriteVerboseLine(data.Message); }; ps.Streams.Warning.DataAdded += (sender, args) => { var data = ((PSDataCollection <WarningRecord>)sender)[args.Index]; psui.WriteWarningLine(data.Message); }; ps.Streams.Error.DataAdded += (sender, args) => { var data = ((PSDataCollection <ErrorRecord>)sender)[args.Index]; psui.WriteErrorLine(data.ErrorDetails?.Message ?? "Error Occured:"); psui.WriteErrorLine(" Id: " + data.FullyQualifiedErrorId); psui.WriteErrorLine(" Category: " + data.CategoryInfo.Category); psui.WriteErrorLine(" Exception:"); psui.WriteErrorLine(data.Exception.Print(2)); if (!string.IsNullOrWhiteSpace(data.ErrorDetails?.RecommendedAction)) { psui.WriteErrorLine(" Recommendation" + data.ErrorDetails?.RecommendedAction); } }; return(ps); }
public override void WriteWarningLine(string message) { _ui.WriteWarningLine(message); }