예제 #1
0
        /// <summary>
        /// Adds Event to Events collection
        /// </summary>
        /// <param name="messageId">Id of the message. The other parts of the message are retreived from resource file by this ID. You need to refer to the file for correct IDs</param>
        /// <param name="messageTextReplacementValues">Array of values to replace placeholders in the Text of the EventMetadata.</param>
        public void Add(int messageId, params string[] messageTextReplacementValues)
        {
            Event evt = new Event();

            #region Get the calling method
            System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace();
            System.Diagnostics.StackFrame stackFrame = null;
            System.Reflection.MethodBase  methodBase = null;
            for (int i = 1; i < 5; i++)       //The trace may be full of our internal stuff which we don't want
            {
                stackFrame = stackTrace.GetFrame(i);
                methodBase = stackFrame.GetMethod();
                if (methodBase.DeclaringType.Name != "Events")
                {
                    break;
                }
            }
            #endregion
            evt.Location    = methodBase.Name;
            evt.EventId     = messageId;
            evt.EventParams = messageTextReplacementValues;
            evt.TimeStamp   = DateTime.Now;
            _Events.Add(evt);
            _blnEventsExist = true;
            #region Set flags that depend on message properties
            switch (EventsMetadata.Event(messageId).Type)
            {
            case System.Diagnostics.EventLogEntryType.Error:
                _blnErrorsExist = true;
                break;

            default:
                _blnAnySuccess = true;
                break;
            }
            #endregion
        }
예제 #2
0
        /// <summary>
        /// Returns hierarchical representation of Events as far as text can go.
        /// </summary>
        /// <param name="entryType">Entry type filter for returned events</param>
        /// <param name="recursionDepth">How deep in the recurtion we are.</param>
        private string ToString(System.Diagnostics.EventLogEntryType?entryType, byte recursionDepth)
        {
            //Group the Events by their Type
            char chaTab = char.Parse("\t");

            System.Diagnostics.EventLogEntryType[] arrEntryTypes;
            if (entryType == null)
            {
                arrEntryTypes    = new System.Diagnostics.EventLogEntryType[3];
                arrEntryTypes[0] = System.Diagnostics.EventLogEntryType.Error;
                arrEntryTypes[1] = System.Diagnostics.EventLogEntryType.Warning;
                arrEntryTypes[2] = System.Diagnostics.EventLogEntryType.Information;
            }
            else
            {
                arrEntryTypes    = new System.Diagnostics.EventLogEntryType[1];
                arrEntryTypes[0] = (System.Diagnostics.EventLogEntryType)entryType;
            }
            System.Text.StringBuilder stbAll = new System.Text.StringBuilder();
            for (int intEntryType = 0; intEntryType < arrEntryTypes.Length; intEntryType++)
            {
                System.Text.StringBuilder stb = new System.Text.StringBuilder();
                #region Output local events
                for (int i = 0; i < _Events.Count; i++)           //We do not provide enumerator for this class. We want things to happen inside
                {
                    Event evt = _Events[i];
                    if (EventsMetadata.Event(evt.EventId).Type == arrEntryTypes[intEntryType])
                    {
                        stb.Append(Environment.NewLine);
//						stb.Append(Environment.NewLine);
                        stb.Append(chaTab, recursionDepth + 1);
                        stb.Append(evt.TimeStamp.ToString(TimeStampFormat)); stb.Append(chaTab);
//USE PADDING !!!!!!!!!!!!!!!!!
                        stb.Append(evt.Location.PadRight(25)); stb.Append(chaTab);
                        stb.Append(EventsMetadata.Event(evt.EventId).ToString(evt.EventParams).Replace(Environment.NewLine, Environment.NewLine + UTILS.Repeat("\t", recursionDepth + 9)));
                    }
                }
                #endregion
                #region Recursively add inner events
                if (_DownstreamEventsCollections.Count > 0)              //Otherwise don't even bother
                //You can still have all the elements of undesireable type, so first find if you have something to report
                {
                    System.Text.StringBuilder stbInner = new System.Text.StringBuilder();
                    for (int ii = 0; ii < _DownstreamEventsCollections.Count; ii++)
                    {
                        string strInnerEvents = _DownstreamEventsCollections[ii].ToString(arrEntryTypes[intEntryType], (byte)(recursionDepth + 1));
                        if (strInnerEvents != "")
                        {
                            stbInner.Append(Environment.NewLine);
                            stbInner.Append(Environment.NewLine);
                            stbInner.Append(chaTab, recursionDepth + 1);
                            stbInner.Append(_DownstreamEventsCollections[ii].OwnerObjectNameForReporting);                            //Type of the object
                            stbInner.Append(":");
                            stbInner.Append(chaTab);
                            stbInner.Append("[");
                            stbInner.Append(_DownstreamEventsCollections[ii].OwnerObjectId);                            //Name of the object
                            stbInner.Append("]");
                            stbInner.Append(strInnerEvents);
                        }
                    }
                    if (stbInner.Length > 0)                   //Then there are inner events to report in this type.
//						if(recursionDepth>0){//In current implementation, the topmost level rarely has own events, but that may change
                    {
                        stb.Append(Environment.NewLine);
                        stb.Append(Environment.NewLine);
                        stb.Append(chaTab, recursionDepth + 1);
                        stb.Append("INNER EVENTS:");
//						}
                        stb.Append(stbInner);
                    }
                }
                #endregion
                #region Append EventType if there is something to append, and we are at the top level of recursion
                if (stb.Length > 0 && recursionDepth == 0)           //Otherwise at the top of the entire thing the Type is already printed
                {
                    stbAll.Append(Environment.NewLine);
                    stbAll.Append(Environment.NewLine);
                    stbAll.Append(Environment.NewLine);
                    stbAll.Append(arrEntryTypes[intEntryType].ToString().ToUpper());
                    switch (arrEntryTypes[intEntryType])
                    {
                    case System.Diagnostics.EventLogEntryType.Error:
                    case System.Diagnostics.EventLogEntryType.Warning:
                        stbAll.Append("S");
                        break;
                    }
                    stbAll.Append(":");
                }
                #endregion

                stbAll.Append(stb);
            }            //for(int intEntryType=0;intEntryType<arrEntryTypes.Length;intEntryType++)
            return(stbAll.ToString());
        }