/// <summary> /// Raises the a telemetry event to all registered loggers. /// </summary> private void RaiseTelemetryEvent(object sender, TelemetryEventArgs buildEvent) { if (TelemetryLogged != null) { try { TelemetryLogged(sender, buildEvent); } catch (LoggerException) { // if a logger has failed politely, abort immediately // first unregister all loggers, since other loggers may receive remaining events in unexpected orderings // if a fellow logger is throwing in an event handler. this.UnregisterAllEventHandlers(); throw; } catch (Exception exception) { // first unregister all loggers, since other loggers may receive remaining events in unexpected orderings // if a fellow logger is throwing in an event handler. this.UnregisterAllEventHandlers(); if (ExceptionHandling.IsCriticalException(exception)) { throw; } InternalLoggerException.Throw(exception, buildEvent, "FatalErrorWhileLogging", false); } } }
/// <summary> /// Create an IForwardingLogger out of the data in this description. This method may throw a variety of /// reflection exceptions if the data is invalid. It is the resposibility of the caller to handle these /// exceptions if desired. /// </summary> /// <returns></returns> internal IForwardingLogger CreateForwardingLogger() { IForwardingLogger forwardingLogger = null; try { forwardingLogger = (IForwardingLogger)CreateLogger(true); // Check if the class was not found in the assembly if (forwardingLogger == null) { InternalLoggerException.Throw(null, null, "LoggerNotFoundError", true, this.Name); } } catch (Exception e /* Wrap all other exceptions in a more meaningful exception*/) { // Two of the possible exceptions are already in reasonable exception types if (e is LoggerException /* Polite logger Failure*/ || e is InternalLoggerException /* LoggerClass not found*/) { throw; } else { if (ExceptionHandling.IsCriticalException(e)) { throw; } InternalLoggerException.Throw(e, null, "LoggerCreationError", true, Name); } } return(forwardingLogger); }
/// <summary> /// Raises a catch-all build event to all registered loggers. /// </summary> /// <param name="sender">sender of the event</param> /// <param name="buildEvent">Build EventArgs</param> /// <exception cref="LoggerException">When EventHandler raises an logger exception the LoggerException is rethrown</exception> /// <exception cref="InternalLoggerException">Any exceptions which are not LoggerExceptions are wrapped in an InternalLoggerException</exception> /// <exception cref="Exception">ExceptionHandling.IsCriticalException exceptions will not be wrapped</exception> private void RaiseAnyEvent(object sender, BuildEventArgs buildEvent) { if (AnyEventRaised != null) { try { AnyEventRaised(sender, buildEvent); } catch (LoggerException exception) { // if a logger has failed politely, abort immediately // first unregister all loggers, since other loggers may receive remaining events in unexpected orderings // if a fellow logger is throwing in an event handler. this.UnregisterAllEventHandlers(); // We ought to dump this farther up the stack, but if for example a task is logging an event within a // catch(Exception) block and not rethrowing it, there's the possibility that this exception could // just get silently eaten. So better to have duplicates than to not log the problem at all. :) ExceptionHandling.DumpExceptionToFile(exception); throw; } catch (Exception exception) { // first unregister all loggers, since other loggers may receive remaining events in unexpected orderings // if a fellow logger is throwing in an event handler. this.UnregisterAllEventHandlers(); // We ought to dump this farther up the stack, but if for example a task is logging an event within a // catch(Exception) block and not rethrowing it, there's the possibility that this exception could // just get silently eaten. So better to have duplicates than to not log the problem at all. :) ExceptionHandling.DumpExceptionToFile(exception); if (ExceptionHandling.IsCriticalException(exception)) { throw; } InternalLoggerException.Throw(exception, buildEvent, "FatalErrorWhileLogging", false); } } }