예제 #1
0
파일: PlugManager.cs 프로젝트: fanoI/IL2CPU
        public PlugManager(LogExceptionDelegate aLogException, Action <string> aLogWarning, TypeResolver typeResolver)
        {
            LogException = aLogException;
            LogWarning   = aLogWarning;

            _typeResolver = typeResolver;
        }
예제 #2
0
        /// <summary>
        /// Logs an Exception.
        /// </summary>
        /// <param name="ex"></param>
        /// <returns></returns>
        public bool LogException(Exception ex)
        {
            LogExceptionDelegate logExDelegate = new LogExceptionDelegate(LogExceptionInternal);
            IAsyncResult         ar            = logExDelegate.BeginInvoke(ex, null, null);

            return(true);
        }
예제 #3
0
        private void HandleException(Exception e)
        {
            string csTemp = "", csMsg = "";

            switch (notificationType)
            {
            case NotificationType.Ask:
            case NotificationType.Inform:
            {
                csTemp = e.Message + "\r\n";
                csMsg  = csTemp;
                csTemp = "[Exception classes]\r\n  " + GetExceptionTypeStack(e) + "\r\n";
                csMsg += csTemp;
                //csTemp = "[Exception messages]\r\n  " + GetExceptionMessageStack(e) + "\r\n";
                //csMsg += csTemp;
                csTemp = "[Stack Traces]\r\n " + GetExceptionCallStack(e);
                csMsg += csTemp;

                MessageBox.Show(csMsg, "Error");
                break;
            }

            case NotificationType.Silent:
                break;
            }

            LogExceptionDelegate logDelegate = new LogExceptionDelegate(LogException);

            logDelegate.BeginInvoke(e, new AsyncCallback(LogCallBack), null);
        }
예제 #4
0
            internal NLogLogger(object logger)
            {
                var loggerType = logger.GetType();

                _nameDelegate = (NameDelegate)loggerType.GetProperty("Name").GetGetMethod().CreateDelegate(typeof(NameDelegate), logger);

                var logEventInfoType = FindType("NLog.LogEventInfo", "NLog");

                _logEventDelegate = (type, e) => loggerType.GetMethod("Log", new Type[] { typeof(Type), logEventInfoType }).Invoke(logger, new object[] { type, e });

                _isTraceEnabledDelegate = GetIsEnabledDelegate(logger, "IsTraceEnabled");
                _isDebugEnabledDelegate = GetIsEnabledDelegate(logger, "IsDebugEnabled");
                _isInfoEnabledDelegate  = GetIsEnabledDelegate(logger, "IsInfoEnabled");
                _isWarnEnabledDelegate  = GetIsEnabledDelegate(logger, "IsWarnEnabled");
                _isErrorEnabledDelegate = GetIsEnabledDelegate(logger, "IsErrorEnabled");
                _isFatalEnabledDelegate = GetIsEnabledDelegate(logger, "IsFatalEnabled");

                _traceDelegate = GetLogDelegate(logger, "Trace");
                _debugDelegate = GetLogDelegate(logger, "Debug");
                _infoDelegate  = GetLogDelegate(logger, "Info");
                _warnDelegate  = GetLogDelegate(logger, "Warn");
                _errorDelegate = GetLogDelegate(logger, "Error");
                _fatalDelegate = GetLogDelegate(logger, "Fatal");

                _traceExceptionDelegate = GetLogExceptionDelegate(logger, "TraceException");
                _debugExceptionDelegate = GetLogExceptionDelegate(logger, "DebugException");
                _infoExceptionDelegate  = GetLogExceptionDelegate(logger, "InfoException");
                _warnExceptionDelegate  = GetLogExceptionDelegate(logger, "WarnException");
                _errorExceptionDelegate = GetLogExceptionDelegate(logger, "ErrorException");
                _fatalExceptionDelegate = GetLogExceptionDelegate(logger, "FatalException");
            }
예제 #5
0
        //internal static LongWaitMessager lwm;
        public void HandleException(Exception e)
        {
            LogExceptionDelegate logDelegate = new LogExceptionDelegate(LogException);

            if (e is System.Reflection.ReflectionTypeLoadException)
            {
                var typeLoadException = e as System.Reflection.ReflectionTypeLoadException;
                foreach (var item in typeLoadException.LoaderExceptions)
                {
                    MessageBox.Show(item.Message.ToString()); MessageBox.Show(item.Message.ToString());
                }
            }
            switch (notificationType)
            {
            case NotificationType.Ask:
                if (MessageBox.Show("An unexpected error occurred - " + e.Message +
                                    ". Do you wish to log the error?", "Error", MessageBoxButton.YesNo) == MessageBoxResult.No)
                {
                    return;
                }
                logDelegate.BeginInvoke(e, new AsyncCallback(LogCallBack), null);
                break;

            case NotificationType.Inform:
                if (counter == 0)
                {
                    counter++;
                    logDelegate.BeginInvoke(e, new AsyncCallback(LogCallBack), null);
                    System.Windows.MessageBox.Show("An unexpected error occurred -\n " + e.Message + "\n\n" + e.StackTrace);
                    //System.Windows.MessageBox.Show("An unexpected error occurred -\n " + e.Message + "\n\n" + e.StackTrace);
                    Thread.Sleep(3);    //capture the screen
                    //lwm = new LongWaitMessager("I'am Try To Process The Exception,Please Waiting...");
                    //lwm.Show();
                    PleaseWaitHelper.Show("I'am Try To Process The Exception,Please Waiting...");
                }
                else
                {
                    textLoggerEvent.Wait(20000);
                    emailLoggerEvent.Wait(20000);
                    //if (lwm!=null)
                    //{
                    //    lwm.Close();
                    //}
                    PleaseWaitHelper.Hide();
                    System.Windows.MessageBox.Show("We Are Sorry To Show This Message To You,\nWe Will Solve The Problem As Soon As Possible, Thanks! \n");
                    Application.Current.Shutdown();
                }

                break;

            case NotificationType.Silent:
                logDelegate.BeginInvoke(e, new AsyncCallback(LogCallBack), null);
                break;
            }
            SaveOnException.SafeInvoke(this);
        }
예제 #6
0
        private void LogCallBack(IAsyncResult result)
        {
            AsyncResult          asyncResult = (AsyncResult)result;
            LogExceptionDelegate logDelegate = (LogExceptionDelegate)asyncResult.AsyncDelegate;

            if (!asyncResult.EndInvokeCalled)
            {
                logDelegate.EndInvoke(result);
            }
        }
예제 #7
0
파일: Debug.cs 프로젝트: tangxiaohui/Koer
 static UDebug()
 {
     enabled = true;
     //enabled = false;
     if (UnityEngine.Debug.isDebugBuild)
     {
         if (enabled)
         {
             _Log          = UnityEngine.Debug.Log;
             _LogError     = UnityEngine.Debug.LogError;
             _LogException = UnityEngine.Debug.LogException;
             _LogWarning   = UnityEngine.Debug.LogWarning;
         }
     }
 }
예제 #8
0
        static UDebug()
        {
            bool editor = false;

#if UNITY_EDITOR
            editor = true;
            if (UnityEditor.EditorApplication.isPlaying == false)
            {
                enabled = true;
            }
#endif
            if (UnityEngine.Debug.isDebugBuild || editor)
            {
                if (enabled)
                {
                    _Log          = UnityEngine.Debug.Log;
                    _LogError     = UnityEngine.Debug.LogError;
                    _LogException = UnityEngine.Debug.LogException;
                    _LogWarning   = UnityEngine.Debug.LogWarning;
                }
            }
        }
예제 #9
0
        private void HandleException(Exception e)
        {
            switch (notificationType)
            {
            case NotificationType.Ask:
                if (MessageBox.Show("An unexpected error occurred - " + e.Message +
                                    ". Do you wish to log the error?", "Error", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
                break;

            case NotificationType.Inform:
                MessageBox.Show("An unexpected error occurred - " + e.Message);
                break;

            case NotificationType.Silent:
                break;
            }

            LogExceptionDelegate logDelegate = new LogExceptionDelegate(LogException);

            logDelegate.BeginInvoke(e, new AsyncCallback(LogCallBack), null);
        }
예제 #10
0
 public PlugManager(LogExceptionDelegate aLogException)
 {
     LogException = aLogException;
 }
예제 #11
0
        private void HandleException(Exception e)
        {
            switch (this.notificationType)
            {
                case NotificationType.Ask:
                    if (MessageBox.Show("An unexpected error occurred - " + e.Message + ". Do you wish to log the error?", "Error", MessageBoxButtons.YesNo) == DialogResult.No)
                    {
                        return;
                    }

                    break;

                case NotificationType.Inform:
                    MessageBox.Show("An unexpected error occurred - " + e.Message);
                    break;

                case NotificationType.Silent:
                    break;
            }

            LogExceptionDelegate logDelegate = new LogExceptionDelegate(this.LogException);
            logDelegate.BeginInvoke(e, new AsyncCallback(this.LogCallBack), null);
        }
예제 #12
0
        private void HandleException(Exception e)
        {
            //if (MessageBox.Show("An unexpected error occurred - " + e.Message +
              //  ". Do you wish to log the error?", "Error", MessageBoxButtons.YesNo) == DialogResult.No)
              //  return;

              LogExceptionDelegate logDelegate = new LogExceptionDelegate(LogException);
              logDelegate.BeginInvoke(e, new AsyncCallback(LogCallBack), null);
        }
예제 #13
0
        private void HandleException(Exception e)
        {
            switch (logType)
            {
                case ExceptionLogType.WebSite:
                case ExceptionLogType.Email:
                    if (MessageBox.Show("An unexpected error occurred - " + e.Message +
                      ". Do you want to submit an error report?", "Error", MessageBoxButtons.YesNo) == DialogResult.No)
                        return;
                    break;
                case ExceptionLogType.EventLog:
                    MessageBox.Show("An unexpected error occurred - " + e.Message +
                      ". It will be logged to the event log", "Error");
                    break;
                case ExceptionLogType.TextFile:
                    MessageBox.Show("An unexpected error occurred - " + e.Message +
                      ". It will be logged to the text file 'BugReport.txt'", "Error");
                    break;
                default:
                    Debug.Assert(false, "Unrecognised log type - " + logType.ToString());
                    break;
            }

            LogExceptionDelegate logDelegate = new LogExceptionDelegate(LogException);
            logDelegate.BeginInvoke(e, new AsyncCallback(LogCallBack), null);
        }
예제 #14
0
            private static bool Initialize()
            {
                try
                {
                    var logEventLevelType = FindType("NLog.LogLevel", "NLog");
                    if (logEventLevelType == null)
                    {
                        throw new LibLogException("Type NLog.LogLevel was not found.");
                    }

                    var levelFields = logEventLevelType.GetFields().ToList();
                    s_levelTrace = levelFields.First(x => x.Name == "Trace").GetValue(null);
                    s_levelDebug = levelFields.First(x => x.Name == "Debug").GetValue(null);
                    s_levelInfo  = levelFields.First(x => x.Name == "Info").GetValue(null);
                    s_levelWarn  = levelFields.First(x => x.Name == "Warn").GetValue(null);
                    s_levelError = levelFields.First(x => x.Name == "Error").GetValue(null);
                    s_levelFatal = levelFields.First(x => x.Name == "Fatal").GetValue(null);

                    var logEventInfoType = FindType("NLog.LogEventInfo", "NLog");
                    if (logEventInfoType == null)
                    {
                        throw new LibLogException("Type NLog.LogEventInfo was not found.");
                    }

                    var loggingEventConstructor =
                        logEventInfoType.GetConstructorPortable(logEventLevelType, typeof(string),
                                                                typeof(IFormatProvider), typeof(string), typeof(object[]), typeof(Exception));

                    var loggerNameParam  = Expression.Parameter(typeof(string));
                    var levelParam       = Expression.Parameter(typeof(object));
                    var messageParam     = Expression.Parameter(typeof(string));
                    var messageArgsParam = Expression.Parameter(typeof(object[]));
                    var exceptionParam   = Expression.Parameter(typeof(Exception));
                    var levelCast        = Expression.Convert(levelParam, logEventLevelType);

                    var newLoggingEventExpression =
                        Expression.New(loggingEventConstructor,
                                       levelCast,
                                       loggerNameParam,
                                       Expression.Constant(null, typeof(IFormatProvider)),
                                       messageParam,
                                       messageArgsParam,
                                       exceptionParam
                                       );

                    s_logEventInfoFact = Expression.Lambda <Func <string, object, string, object[], Exception, object> >(
                        newLoggingEventExpression,
                        loggerNameParam, levelParam, messageParam, messageArgsParam, exceptionParam).Compile();

                    var loggerType = FindType("NLog.Logger", "NLog");

                    s_loggerNameDelegate = GetLoggerNameDelegate(loggerType);

                    s_logEventDelegate = GetLogEventDelegate(loggerType, logEventInfoType);

                    s_isTraceEnabledDelegate = GetIsEnabledDelegate(loggerType, "IsTraceEnabled");
                    s_isDebugEnabledDelegate = GetIsEnabledDelegate(loggerType, "IsDebugEnabled");
                    s_isInfoEnabledDelegate  = GetIsEnabledDelegate(loggerType, "IsInfoEnabled");
                    s_isWarnEnabledDelegate  = GetIsEnabledDelegate(loggerType, "IsWarnEnabled");
                    s_isErrorEnabledDelegate = GetIsEnabledDelegate(loggerType, "IsErrorEnabled");
                    s_isFatalEnabledDelegate = GetIsEnabledDelegate(loggerType, "IsFatalEnabled");

                    s_traceDelegate = GetLogDelegate(loggerType, "Trace");
                    s_debugDelegate = GetLogDelegate(loggerType, "Debug");
                    s_infoDelegate  = GetLogDelegate(loggerType, "Info");
                    s_warnDelegate  = GetLogDelegate(loggerType, "Warn");
                    s_errorDelegate = GetLogDelegate(loggerType, "Error");
                    s_fatalDelegate = GetLogDelegate(loggerType, "Fatal");

                    s_traceExceptionDelegate = GetLogExceptionDelegate(loggerType, "TraceException");
                    s_debugExceptionDelegate = GetLogExceptionDelegate(loggerType, "DebugException");
                    s_infoExceptionDelegate  = GetLogExceptionDelegate(loggerType, "InfoException");
                    s_warnExceptionDelegate  = GetLogExceptionDelegate(loggerType, "WarnException");
                    s_errorExceptionDelegate = GetLogExceptionDelegate(loggerType, "ErrorException");
                    s_fatalExceptionDelegate = GetLogExceptionDelegate(loggerType, "FatalException");

                    s_structuredLoggingEnabled = IsStructuredLoggingEnabled();
                }
                catch (Exception ex)
                {
                    s_initializeException = ex;
                    return(false);
                }

                return(true);
            }
예제 #15
0
 public PlugManager(LogExceptionDelegate aLogException, Action<string> aLogWarning)
 {
     LogException = aLogException;
     LogWarning = aLogWarning;
 }
 public LogExceptionConsumerPipe(LogExceptionDelegate logFunc)
 {
     _logFunc = logFunc;
 }
예제 #17
0
 public PlugManager(LogExceptionDelegate aLogException, ScanMethodDelegate aScanMethod, QueueDelegate aQueueMethod)
 {
     LogException = aLogException;
     ScanMethod   = aScanMethod;
     Queue        = aQueueMethod;
 }
예제 #18
0
 public PlugManager(LogExceptionDelegate aLogException, Action <string> aLogWarning)
 {
     LogException = aLogException;
     LogWarning   = aLogWarning;
 }
예제 #19
0
파일: PlugManager.cs 프로젝트: Orvid/Cosmos
 public PlugManager(LogExceptionDelegate aLogException)
 {
     LogException = aLogException;
 }
예제 #20
0
파일: PlugManager.cs 프로젝트: Orvid/Cosmos
 public PlugManager(LogExceptionDelegate aLogException, ScanMethodDelegate aScanMethod, QueueDelegate aQueueMethod)
 {
     LogException = aLogException;
     ScanMethod = aScanMethod;
     Queue = aQueueMethod;
 }
예제 #21
0
            static NLogLogger()
            {
                try
                {
                    var logEventLevelType = Type.GetType("NLog.LogLevel, NLog");
                    if (logEventLevelType == null)
                    {
                        throw new InvalidOperationException("Type NLog.LogLevel was not found.");
                    }

                    var levelFields = logEventLevelType.GetFields().ToList();
                    _levelTrace = levelFields.First(x => x.Name == "Trace").GetValue(null);
                    _levelDebug = levelFields.First(x => x.Name == "Debug").GetValue(null);
                    _levelInfo  = levelFields.First(x => x.Name == "Info").GetValue(null);
                    _levelWarn  = levelFields.First(x => x.Name == "Warn").GetValue(null);
                    _levelError = levelFields.First(x => x.Name == "Error").GetValue(null);
                    _levelFatal = levelFields.First(x => x.Name == "Fatal").GetValue(null);

                    var logEventInfoType = Type.GetType("NLog.LogEventInfo, NLog");
                    if (logEventInfoType == null)
                    {
                        throw new InvalidOperationException("Type NLog.LogEventInfo was not found.");
                    }

                    var loggingEventConstructor = logEventInfoType.GetConstructor(new []
                    {
                        logEventLevelType,
                        typeof(string),
                        typeof(IFormatProvider),
                        typeof(string),
                        typeof(object[]),
                        typeof(Exception),
                    });
                    ParameterExpression loggerNameParam  = Expression.Parameter(typeof(string));
                    ParameterExpression levelParam       = Expression.Parameter(typeof(object));
                    ParameterExpression messageParam     = Expression.Parameter(typeof(string));
                    ParameterExpression messageArgsParam = Expression.Parameter(typeof(object[]));
                    ParameterExpression exceptionParam   = Expression.Parameter(typeof(Exception));
                    UnaryExpression     levelCast        = Expression.Convert(levelParam, logEventLevelType);

                    NewExpression newLoggingEventExpression =
                        Expression.New(loggingEventConstructor,
                                       levelCast,
                                       loggerNameParam,
                                       Expression.Constant(null, typeof(IFormatProvider)),
                                       messageParam,
                                       messageArgsParam,
                                       exceptionParam
                                       );

                    _logEventInfoFact = Expression.Lambda <Func <string, object, string, object[], Exception, object> >(
                        newLoggingEventExpression,
                        loggerNameParam, levelParam, messageParam, messageArgsParam, exceptionParam).Compile();

                    Type loggerType = Type.GetType("NLog.Logger, NLog");

                    _loggerNameDelegate = GetLoggerNameDelegate(loggerType);

                    _logEventDelegate = GetLogEventDelegate(loggerType, logEventInfoType);

                    _isTraceEnabledDelegate = GetIsEnabledDelegate(loggerType, "IsTraceEnabled");
                    _isDebugEnabledDelegate = GetIsEnabledDelegate(loggerType, "IsDebugEnabled");
                    _isInfoEnabledDelegate  = GetIsEnabledDelegate(loggerType, "IsInfoEnabled");
                    _isWarnEnabledDelegate  = GetIsEnabledDelegate(loggerType, "IsWarnEnabled");
                    _isErrorEnabledDelegate = GetIsEnabledDelegate(loggerType, "IsErrorEnabled");
                    _isFatalEnabledDelegate = GetIsEnabledDelegate(loggerType, "IsFatalEnabled");

                    _traceDelegate = GetLogDelegate(loggerType, "Trace");
                    _debugDelegate = GetLogDelegate(loggerType, "Debug");
                    _infoDelegate  = GetLogDelegate(loggerType, "Info");
                    _warnDelegate  = GetLogDelegate(loggerType, "Warn");
                    _errorDelegate = GetLogDelegate(loggerType, "Error");
                    _fatalDelegate = GetLogDelegate(loggerType, "Fatal");

                    _traceExceptionDelegate = GetLogExceptionDelegate(loggerType, "TraceException");
                    _debugExceptionDelegate = GetLogExceptionDelegate(loggerType, "DebugException");
                    _infoExceptionDelegate  = GetLogExceptionDelegate(loggerType, "InfoException");
                    _warnExceptionDelegate  = GetLogExceptionDelegate(loggerType, "WarnException");
                    _errorExceptionDelegate = GetLogExceptionDelegate(loggerType, "ErrorException");
                    _fatalExceptionDelegate = GetLogExceptionDelegate(loggerType, "FatalException");

                    _structuredLoggingEnabled = IsStructuredLoggingEnabled();
                }
                catch { }
            }