internal static void WriteException(System.Management.Automation.ErrorRecord error) { if (ExecutingCmdlet != null) { ExecutingCmdlet.WriteError(error); } else { Console.WriteLine(error.ToString()); } if (!string.IsNullOrEmpty(LogFile)) { File.AppendAllText(LogFile, error.ToString() + "\r\n"); } }
/// <summary> /// Logs the specified STR. /// </summary> /// <param name="message">The message.</param> /// <param name="msgType">Type of the MSG.</param> /// <param name="args">The args.</param> internal static void Write(string message, EventLogEntryType msgType, params string[] args) { if (string.IsNullOrEmpty(message)) { return; } message = string.Format(message, args); if (ExecutingCmdlet != null) { if (msgType == EventLogEntryType.Warning) { ExecutingCmdlet.WriteWarning(message); } else if (msgType == EventLogEntryType.Error) { ExecutingCmdlet.WriteError(new System.Management.Automation.ErrorRecord(new Exception(message), null, System.Management.Automation.ErrorCategory.NotSpecified, null)); } ExecutingCmdlet.WriteVerbose(message); } else { if (msgType == EventLogEntryType.Warning && !message.ToUpper().StartsWith("WARNING:")) { message = "WARNING: " + message; } if (msgType != EventLogEntryType.Information || Verbose) { Console.WriteLine(message); } } if (!string.IsNullOrEmpty(LogFile)) { File.AppendAllText(LogFile, message + "\r\n"); } }