Пример #1
0
        /// <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="ModuleName">The name of the module the function writing the error came from</param>
        /// <param name="Tags">The tags that were assigned to the error event</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>
        /// <param name="ComputerName">The computer the error was written on</param>
        /// <returns>The error entry, so it may be included in the message generated</returns>
        public static PsfExceptionRecord WriteErrorEntry(ErrorRecord[] Record, string FunctionName, string ModuleName, List <string> Tags, DateTime Timestamp, string Message, Guid Runspace, string ComputerName)
        {
            PsfExceptionRecord tempRecord = new PsfExceptionRecord(Runspace, ComputerName, Timestamp, FunctionName, ModuleName, Tags, Message);

            foreach (ErrorRecord rec in Record)
            {
                tempRecord.Exceptions.Add(new PsfException(rec, FunctionName, Timestamp, Message, Runspace, ComputerName));
            }

            if (ErrorLogFileEnabled)
            {
                OutQueueError.Enqueue(tempRecord);
            }
            if (ErrorLogEnabled)
            {
                ErrorRecords.Enqueue(tempRecord);
            }

            PsfExceptionRecord tmp;

            while ((MaxErrorCount > 0) && (ErrorRecords.Count > MaxErrorCount))
            {
                ErrorRecords.TryDequeue(out tmp);
            }
            return(tempRecord);
        }
Пример #2
0
 /// <summary>
 /// Creates a filled out log entry
 /// </summary>
 /// <param name="Message">The message that was logged</param>
 /// <param name="Type">The type(s) of message written</param>
 /// <param name="Timestamp">When was the message logged</param>
 /// <param name="FunctionName">What function wrote the message</param>
 /// <param name="ModuleName">Name of the module the function writing this message came from</param>
 /// <param name="Tags">Tags that were applied to the message</param>
 /// <param name="Level">What level was the message written at.</param>
 /// <param name="Runspace">The ID of the runspace that wrote the message.</param>
 /// <param name="ComputerName">The computer the message was generated on.</param>
 /// <param name="TargetObject">The object this message was all about.</param>
 /// <param name="File">The file of the code that wrote the message.</param>
 /// <param name="Line">The line on which the message was written.</param>
 /// <param name="CallStack">The callstack that triggered the write.</param>
 /// <param name="Username">The user responsible for running the code that is writing the message.</param>
 /// <param name="ErrorRecord">An associated error item.</param>
 public LogEntry(string Message, LogEntryType Type, DateTime Timestamp, string FunctionName, string ModuleName, List <string> Tags, MessageLevel Level, Guid Runspace, string ComputerName, object TargetObject, string File, int Line, CallStack CallStack, string Username, PsfExceptionRecord ErrorRecord)
 {
     this.Message      = Message;
     this.Type         = Type;
     this.Timestamp    = Timestamp;
     this.FunctionName = FunctionName;
     this.ModuleName   = ModuleName;
     this.Tags         = Tags;
     this.Level        = Level;
     this.Runspace     = Runspace;
     this.ComputerName = ComputerName;
     this.TargetObject = TargetObject;
     this.File         = File;
     this.Line         = Line;
     this.CallStack    = CallStack;
     this.Username     = Username;
     this.ErrorRecord  = ErrorRecord;
 }
Пример #3
0
 /// <summary>
 /// Retrieves a copy of the Error stack
 /// </summary>
 /// <returns>All errors thrown by functions using the message or flowcontrol system</returns>
 public static PsfExceptionRecord[] GetErrors()
 {
     PsfExceptionRecord[] temp = new PsfExceptionRecord[ErrorRecords.Count];
     ErrorRecords.CopyTo(temp, 0);
     return(temp);
 }
Пример #4
0
        /// <summary>
        /// Write a new entry to the log
        /// </summary>
        /// <param name="Message">The message to log</param>
        /// <param name="Type">The type of the message logged</param>
        /// <param name="Timestamp">When was the message generated</param>
        /// <param name="FunctionName">What function wrote the message</param>
        /// <param name="ModuleName">What module did the function writing this message come from?</param>
        /// <param name="Tags">The tags that were applied to the message</param>
        /// <param name="Level">At what level was the function written</param>
        /// <param name="Runspace">The runspace the message is coming from</param>
        /// <param name="ComputerName">The computer the message was generated on</param>
        /// <param name="File">The file from which the message was written</param>
        /// <param name="Line">The line on which the message was written</param>
        /// <param name="TargetObject">The object associated with a given message.</param>
        /// <param name="CallStack">The callstack at the moment the message was written.</param>
        /// <param name="Username">The name of the user under which the code being executed</param>
        /// <param name="ErrorRecord">An associated error record</param>
        /// <returns>The entry that is being written</returns>
        public static LogEntry WriteLogEntry(string Message, LogEntryType Type, DateTime Timestamp, string FunctionName, string ModuleName, List <string> Tags, MessageLevel Level, Guid Runspace, string ComputerName, string File, int Line, IEnumerable <CallStackFrame> CallStack, string Username, PsfExceptionRecord ErrorRecord, object TargetObject = null)
        {
            LogEntry temp = new LogEntry(Message, Type, Timestamp, FunctionName, ModuleName, Tags, Level, Runspace, ComputerName, TargetObject, File, Line, new PSFramework.Message.CallStack(CallStack), Username, ErrorRecord);

            if (MessageLogFileEnabled)
            {
                OutQueueLog.Enqueue(temp);
            }
            if (MessageLogEnabled)
            {
                LogEntries.Enqueue(temp);
            }

            LogEntry tmp;

            while ((MaxMessageCount > 0) && (LogEntries.Count > MaxMessageCount))
            {
                LogEntries.TryDequeue(out tmp);
            }

            return(temp);
        }
Пример #5
0
 /// <summary>
 /// Write a new entry to the log
 /// </summary>
 /// <param name="Message">The message to log</param>
 /// <param name="Type">The type of the message logged</param>
 /// <param name="Timestamp">When was the message generated</param>
 /// <param name="FunctionName">What function wrote the message</param>
 /// <param name="ModuleName">What module did the function writing this message come from?</param>
 /// <param name="Tags">The tags that were applied to the message</param>
 /// <param name="Level">At what level was the function written</param>
 /// <param name="Runspace">The runspace the message is coming from</param>
 /// <param name="ComputerName">The computer the message was generated on</param>
 /// <param name="File">The file from which the message was written</param>
 /// <param name="Line">The line on which the message was written</param>
 /// <param name="TargetObject">The object associated with a given message.</param>
 /// <param name="CallStack">The callstack at the moment the message was written.</param>
 /// <param name="Username">The name of the user under which the code being executed</param>
 /// <param name="ErrorRecord">An associated error record</param>
 /// <returns>The entry that is being written</returns>
 public static LogEntry WriteLogEntry(string Message, LogEntryType Type, DateTime Timestamp, string FunctionName, string ModuleName, List <string> Tags, MessageLevel Level, Guid Runspace, string ComputerName, string File, int Line, IEnumerable <CallStackFrame> CallStack, string Username, PsfExceptionRecord ErrorRecord, object TargetObject = null)
 {
     return(WriteLogEntry(Message, Type, Timestamp, FunctionName, ModuleName, Tags, Level, Runspace, ComputerName, File, Line, CallStack, Username, ErrorRecord, "", null, TargetObject));
 }