Exemplo n.º 1
0
        public void HandleEvent(LogLevel nlogLevel, string message, Exception exception, string category)
        {
            if (nlogLevel == LogLevel.Error || nlogLevel == LogLevel.Fatal || nlogLevel == LogLevel.Warn)
            {
                if (nlogLevel == LogLevel.Warn)
                {
                    WarnCount++;
                }
                else
                {
                    ErrorCount++;
                }

                try
                {
                    OnErrorCountChanged();
                }
                catch (Exception handlingException)
                {
                    // calling logger directly to avoid enless loop of this error
                    factoryLogger.Error(handlingException, "Error at OnErrorCountChanged");
                }
            }

            var args = new LogMessageEventArgs(nlogLevel, message, exception, category);

            var handler = EventLogged;

            if (handler != null)
            {
                try
                {
                    threadMarshaller.Marshal(() => handler(this, args));
                }
                catch (Exception handlingException)
                {
                    // calling logger directly to avoid endless loop of this error
                    factoryLogger.Error(handlingException, "Error during log event forwarding");
                }
            }
            else
            {
                // necessary because there is a small delay before LogView is resolved.
                AddToMissedEvents(args);
            }
        }
Exemplo n.º 2
0
 private void HandleCommandComplete(int exitCode, string output, string error,
                                    CommandCompleteHandler continuation, CommandCompleteHandler externalCallback)
 {
     try
     {
         bool   success = exitCode == 0;
         string message = success ? output : error;
         continuation(success, message);
         externalCallback?.Invoke(success, message);
     }
     catch (Exception e)
     {
         // marshal exceptions back to main thread for Unity to handle them
         _threadMarshaller.Marshal(() => Throw(e));
     }
 }