/// <summary> /// Write an error record to the log /// </summary> /// <param name="Record">The actual error record as powershell wrote it</param> /// <param name="FunctionName">The name of the function writing the error</param> /// <param name="Timestamp">When was the error written</param> /// <param name="Message">What message was passed to the user</param> /// <param name="Runspace">The runspace the message was written from</param> public static void WriteErrorEntry(ErrorRecord[] Record, string FunctionName, DateTime Timestamp, string Message, Guid Runspace) { DbatoolsExceptionRecord tempRecord = new DbatoolsExceptionRecord(Runspace, Timestamp, FunctionName, Message); foreach (ErrorRecord rec in Record) { tempRecord.Exceptions.Add(new DbatoolsException(rec, FunctionName, Timestamp, Message, Runspace)); } if (ErrorLogFileEnabled) { OutQueueError.Enqueue(tempRecord); } if (ErrorLogEnabled) { ErrorRecords.Enqueue(tempRecord); } DbatoolsExceptionRecord tmp; while ((MaxErrorCount > 0) && (ErrorRecords.Count > MaxErrorCount)) { ErrorRecords.TryDequeue(out tmp); } }
/// <summary> /// Retrieves a copy of the Error stack /// </summary> /// <returns>All errors thrown by dbatools functions</returns> public static DbatoolsExceptionRecord[] GetErrors() { DbatoolsExceptionRecord[] temp = new DbatoolsExceptionRecord[ErrorRecords.Count]; ErrorRecords.CopyTo(temp, 0); return(temp); }