Exemplo n.º 1
0
        public void CanGetFormattedEntryWithMessageAndExceptionAndExtraInformation()
        {
            EventLogEntryFormatter formatter = new EventLogEntryFormatter(applicationName, blockName);
            Exception ex = null;

            string[] extraInformation = new string[] { extraInformation1, extraInformation2 };

            try
            {
                throw new Exception(exceptionMessage);
            }
            catch (Exception e)
            {
                ex = e;
            }

            string entryText = formatter.GetEntryText(errorMessage, ex, extraInformation);

            Assert.IsNotNull(entryText);
            Assert.IsTrue(entryText.IndexOf(errorMessage) > 0);
            Assert.IsTrue(entryText.IndexOf(applicationName) > 0);
            Assert.IsTrue(entryText.IndexOf(blockName) > 0);
            Assert.IsTrue(entryText.IndexOf(exceptionMessage) > 0);
            Assert.IsTrue(entryText.IndexOf(extraInformation1) > 0);
            Assert.IsTrue(entryText.IndexOf(extraInformation2) > 0);
        }
Exemplo n.º 2
0
        public void ConnectionFailed(object sender, ConnectionFailedEventArgs e)
        {
            if (PerformanceCountersEnabled)
            {
                connectionFailedCounter.Increment();
            }
            if (WmiEnabled)
            {
                FireManagementInstrumentation(new ConnectionFailedEvent(instanceName, e.ConnectionString, e.Exception.ToString()));
            }
            if (EventLoggingEnabled)
            {
                string errorMessage
                    = string.Format(
                          Resources.Culture,
                          Resources.ErrorConnectionFailedMessage,
                          instanceName);
                string extraInformation
                    = string.Format(
                          Resources.Culture,
                          Resources.ErrorConnectionFailedExtraInformation,
                          e.ConnectionString);
                string entryText = new EventLogEntryFormatter(Resources.BlockName).GetEntryText(errorMessage, e.Exception, extraInformation);

                EventLog.WriteEntry(GetEventSourceName(), entryText, EventLogEntryType.Error);
            }
        }
        public void CanGetFormattedEntryWithMessageAndExceptionAndExtraInformation()
        {
            EventLogEntryFormatter formatter = new EventLogEntryFormatter(applicationName, blockName);
            Exception ex = null;
            string[] extraInformation = new string[] { extraInformation1, extraInformation2 };

            try
            {
                throw new Exception(exceptionMessage);
            }
            catch (Exception e)
            {
                ex = e;
            }

            string entryText = formatter.GetEntryText(errorMessage, ex, extraInformation);

            Assert.IsNotNull(entryText);
            Assert.IsTrue(entryText.IndexOf(errorMessage) > 0);
            Assert.IsTrue(entryText.IndexOf(applicationName) > 0);
            Assert.IsTrue(entryText.IndexOf(blockName) > 0);
            Assert.IsTrue(entryText.IndexOf(exceptionMessage) > 0);
            Assert.IsTrue(entryText.IndexOf(extraInformation1) > 0);
            Assert.IsTrue(entryText.IndexOf(extraInformation2) > 0);
        }
Exemplo n.º 4
0
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Default handler for the <see cref="NewDataInstrumentationProvider.FireConnectionFailedEvent"/> event.
        /// </summary>
        /// <remarks>
        /// Increments the "Connections Failed/sec" performance counter and writes
        /// an error entry to the event log.
        /// </remarks>
        /// <param name="connectionString">The connection string that caused the failed connection, with credentials removed.</param>
        /// <param name="exception">The exception thrown when the connection failed.</param>
        public void FireConnectionFailedEvent(string connectionString, Exception exception)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }

            if (PerformanceCountersEnabled)
            {
                connectionFailedCounter.Increment();
                totalConnectionFailedCounter.Increment();
            }
            if (EventLoggingEnabled)
            {
                string errorMessage
                    = string.Format(
                          CultureInfo.CurrentCulture,
                          Resources.ErrorConnectionFailedMessage,
                          instanceName);
                string extraInformation
                    = string.Format(
                          CultureInfo.CurrentCulture,
                          Resources.ErrorConnectionFailedExtraInformation,
                          connectionString);
                string entryText = new EventLogEntryFormatter(Resources.BlockName).GetEntryText(errorMessage, exception, extraInformation);

                EventLog.WriteEntry(GetEventSourceName(), entryText, EventLogEntryType.Error);
            }
        }
Exemplo n.º 5
0
        public void CanGetFormattedEntryWithMessage()
        {
            EventLogEntryFormatter formatter = new EventLogEntryFormatter(applicationName, blockName);
            string entryText = formatter.GetEntryText(errorMessage);

            Assert.IsNotNull(entryText);
            Assert.IsTrue(entryText.IndexOf(applicationName) > 0);
            Assert.IsTrue(entryText.IndexOf(blockName) > 0);
            Assert.IsTrue(entryText.IndexOf(errorMessage) > 0);
        }
        public void CanGetFormattedEntryWithMessage()
        {
            EventLogEntryFormatter formatter = new EventLogEntryFormatter(applicationName, blockName);

            string entryText = formatter.GetEntryText(errorMessage);

            Assert.IsNotNull(entryText);
            Assert.IsTrue(entryText.IndexOf(applicationName) > 0);
            Assert.IsTrue(entryText.IndexOf(blockName) > 0);
            Assert.IsTrue(entryText.IndexOf(errorMessage) > 0);
        }
        public void CanGetFormattedEntryWithMessageAndExtraInformation()
        {
            EventLogEntryFormatter formatter = new EventLogEntryFormatter(applicationName, blockName);
            string[] extraInformation = new string[] { extraInformation1, extraInformation2 };

            string entryText = formatter.GetEntryText(errorMessage, extraInformation);

            Assert.IsNotNull(entryText);
            Assert.IsTrue(entryText.IndexOf(applicationName) > 0);
            Assert.IsTrue(entryText.IndexOf(blockName) > 0);
            Assert.IsTrue(entryText.IndexOf(errorMessage) > 0);
            Assert.IsTrue(entryText.IndexOf(extraInformation1) > 0);
            Assert.IsTrue(entryText.IndexOf(extraInformation2) > 0);
        }
Exemplo n.º 8
0
        public void CanGetFormattedEntryWithMessageAndExtraInformation()
        {
            EventLogEntryFormatter formatter = new EventLogEntryFormatter(applicationName, blockName);

            string[] extraInformation = new string[] { extraInformation1, extraInformation2 };
            string   entryText        = formatter.GetEntryText(errorMessage, extraInformation);

            Assert.IsNotNull(entryText);
            Assert.IsTrue(entryText.IndexOf(applicationName) > 0);
            Assert.IsTrue(entryText.IndexOf(blockName) > 0);
            Assert.IsTrue(entryText.IndexOf(errorMessage) > 0);
            Assert.IsTrue(entryText.IndexOf(extraInformation1) > 0);
            Assert.IsTrue(entryText.IndexOf(extraInformation2) > 0);
        }
        /// <summary>
        /// Report the <see cref="IExceptionHandlingInstrumentationProvider.FireExceptionHandlingErrorOccurred"/> to instrumentation.
        /// </summary>
        /// <param name="errorMessage">Message describing the error.</param>
        public void FireExceptionHandlingErrorOccurred(string errorMessage)
        {
            if (EventLoggingEnabled)
            {
                string message
                    = string.Format(
                          CultureInfo.CurrentCulture,
                          Resources.ErrorHandlingExceptionMessage,
                          instanceName);
                string entryText = new EventLogEntryFormatter(Resources.BlockName).GetEntryText(message, errorMessage);

                EventLog.WriteEntry(GetEventSourceName(), entryText, EventLogEntryType.Error);
            }
        }
 public void ExceptionHandlingErrorOccurred(object sender, ExceptionHandlingErrorEventArgs e)
 {
     if (EventLoggingEnabled)
     {
         string errorMessage
             = string.Format(
                   Resources.Culture,
                   Resources.ErrorHandlingExceptionMessage,
                   instanceName);
         string entryText = new EventLogEntryFormatter(Resources.BlockName).GetEntryText(errorMessage, e.Message);
         EventLog.WriteEntry(GetEventSourceName(), entryText, EventLogEntryType.Error);
     }
     if (WmiEnabled)
     {
         FireManagementInstrumentation(new ExceptionHandlingFailureEvent(instanceName, e.Message));
     }
 }
Exemplo n.º 11
0
        public void CyptographicOperationFailed(object sender, CrytographicOperationErrorEventArgs e)
        {
            if (EventLoggingEnabled)
            {
                string errorMessage
                    = string.Format(
                          Resources.Culture,
                          Resources.ErrorCryptographicOperationFailed,
                          instanceName);
                string entryText = new EventLogEntryFormatter(Resources.BlockName).GetEntryText(errorMessage, e.Exception, e.Message);

                EventLog.WriteEntry(GetEventSourceName(), entryText, EventLogEntryType.Error);
            }
            if (WmiEnabled)
            {
                ManagementInstrumentation.Fire(new HashOperationFailedEvent(instanceName, e.Message, e.Exception.ToString()));
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="message">The message that describes the failure.</param>
        /// <param name="exception">The exception thrown during the failure.</param>
        public void FireCyptographicOperationFailed(string message, Exception exception)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }

            if (EventLoggingEnabled)
            {
                string errorMessage
                    = string.Format(
                          CultureInfo.CurrentCulture,
                          Resources.ErrorCryptographicOperationFailed,
                          instanceName);
                string entryText = new EventLogEntryFormatter(Resources.BlockName).GetEntryText(errorMessage, exception, message);

                EventLog.WriteEntry(GetEventSourceName(), entryText, EventLogEntryType.Error);
            }
        }