Пример #1
0
        /// <summary>
        /// Traces a message to the event log with the specified level
        /// </summary>
        /// <param name="componentName">Calling component ID</param>
        /// <param name="eventLevel">severity of event</param>
        /// <param name="message">exception text</param>
        public static void TraceEventLogEntry(ComponentId componentName, XlTraceLevel eventLevel, string message)
        {
            // Update the event log source
            if (eventLog.Source.Length == 0)
            {
                switch (componentName)
                {
                case ComponentId.XllConnector:
                    eventLog.Source = "XllConnector";
                    break;

                case ComponentId.XllContainer:
                    eventLog.Source = "XllContainer";
                    break;

                case ComponentId.ExcelDriver:
                    eventLog.Source = "ExcelDriver";
                    break;

                case ComponentId.ExcelClient:
                    eventLog.Source = "ExcelClient";
                    break;

                case ComponentId.ExcelService:
                    eventLog.Source = "ExcelService";
                    break;
                }
            }

            // Convert the XlTraceLevel to the event log level
            EventLogEntryType type = EventLogEntryType.Information;

            switch (eventLevel)
            {
            case XlTraceLevel.Critical:
            case XlTraceLevel.Error:
                type = EventLogEntryType.Error;
                break;

            case XlTraceLevel.Warning:
                type = EventLogEntryType.Warning;
                break;

            case XlTraceLevel.Information:
            case XlTraceLevel.Verbose:
                type = EventLogEntryType.Information;
                break;
            }

            // Write the event log entry
            string traceString = CombineTraceString(componentName, message);

            eventLog.WriteEntry(traceString, type);
        }
Пример #2
0
        /// <summary>
        /// Traces using Crimson and an event from the event manifest, if possible, and traces using the event log if not possible.
        /// </summary>
        /// <param name="eventLevel">The level of the event (used for event log tracing only)</param>
        /// <param name="componentName">The name of the calling component </param>
        /// <param name="message">The text of the exception or error that is being logged (used for event log tracing only)</param>
        /// <param name="eventWriter">A method that will trace the event with Crimson if it can be used</param>
        public static void TraceEvent(XlTraceLevel eventLevel, ComponentId componentName, string message, EventWriterCallback eventWriter)
        {
            if (CanUseCrimson())
            {
                // This is running Vista or later. Use Crimson.
                eventWriter();
            }
            else
            {
                // Running XP. Use the event log.
                TraceEventLogEntry(componentName, eventLevel, message);
            }

            // Also use SOA tracing if SOA_TRACING is defined
            SoaTrace(eventLevel, componentName, message);
        }
Пример #3
0
        /// <summary>
        /// Traces a message with SOA
        /// </summary>
        /// <param name="eventLevel">Severity of the event</param>
        /// <param name="message">error text to write to event</param>
        /// <param name="parameters">parameters for message string</param>
        public static void SoaTrace(XlTraceLevel eventLevel, ComponentId componentName, string message, params object[] parameters)
        {
            string traceString = CombineTraceString(componentName, message, parameters);

            SoaTrace(eventLevel, traceString);
        }
Пример #4
0
        /// <summary>
        /// Traces a message with SOA
        /// </summary>
        /// <param name="eventLevel">Severity of the event</param>
        /// <param name="message">error text to write to event</param>
        /// <param name="parameters">parameters for message string</param>
        public static void SoaTrace(XlTraceLevel eventLevel, string message, params object[] parameters)
        {
#if DEBUG
            _traceSource.TraceInformation(message, parameters);
#endif
            if (!soaTracingEnabled)
            {
                return;
            }

            string traceString = string.Format(message, parameters);
            try
            {
                switch (eventLevel)
                {
                case XlTraceLevel.Critical:
                    if (ServiceContext.Logger.Switch.ShouldTrace(TraceEventType.Critical))
                    {
                        ServiceContext.Logger.TraceEvent(TraceEventType.Critical, 0, traceString);
                    }

                    break;

                case XlTraceLevel.Error:
                    if (ServiceContext.Logger.Switch.ShouldTrace(TraceEventType.Error))
                    {
                        ServiceContext.Logger.TraceEvent(TraceEventType.Error, 0, traceString);
                    }

                    break;

                case XlTraceLevel.Warning:
                    if (ServiceContext.Logger.Switch.ShouldTrace(TraceEventType.Warning))
                    {
                        ServiceContext.Logger.TraceEvent(TraceEventType.Warning, 0, traceString);
                    }

                    break;

                case XlTraceLevel.Information:
                    if (ServiceContext.Logger.Switch.ShouldTrace(TraceEventType.Information))
                    {
                        ServiceContext.Logger.TraceEvent(TraceEventType.Information, 0, traceString);
                    }

                    break;

                case XlTraceLevel.Verbose:
                    if (ServiceContext.Logger.Switch.ShouldTrace(TraceEventType.Verbose))
                    {
                        ServiceContext.Logger.TraceEvent(TraceEventType.Verbose, 0, traceString);
                    }

                    break;
                }
            }
            catch (Exception)
            {
                // Trace the exception?
            }
        }