Exemple #1
0
        private static Log4NetException getExceptioObj(ref object[] Params)
        {
            if ((Params == null) || (Params.Length <= 0))
            {
                return(null);
            }

            Log4NetException TISExc = null;
            Type             obj1   = typeof(Exception);

            object[] newParams = new object[Params.GetLength(0)];
            newParams[Params.GetLength(0) - 1] = string.Empty;

            int index = 0;

            foreach (object oParam in Params)
            {
                if (oParam != null)
                {
                    var obj2 = oParam.GetType();
                    if (obj1.IsAssignableFrom(obj2))
                    {
                        TISExc = new Log4NetException((oParam as Exception).Message, oParam as Exception);
                    }
                    else
                    {
                        newParams[index++] = oParam;
                    }
                }
            }

            Params = newParams;
            return(TISExc);
        }
Exemple #2
0
        /// Output message according with logging Level.
        /// </summary>
        /// <param name="log"> log4Net object.</param>
        /// <param name="loggingLevel">The Severity level.</param>
        /// <param name="message">The message.</param>
        /// <param name="exception">Any exception to be logged.</param>
        ///
        private static void LogBase(ILog log, Severity loggingLevel, string message, Log4NetException exception)
        {
            if (ShouldLog(log, loggingLevel))
            {
                switch (loggingLevel)
                {
                case Severity.DEBUG:
                case Severity.DETAILED_DEBUG:
                    log.Debug(message, exception);
                    break;

                case Severity.INFO:
                    log.Info(message, exception);
                    break;

                case Severity.WARNING:
                    log.Warn(message, exception);
                    break;

                case Severity.ERROR:
                    log.Error(message, exception);
                    break;

                case Severity.FATAL_ERROR:
                    log.Fatal(message, exception);
                    break;
                }
            }
        }
Exemple #3
0
        public static void Write(Severity enSeverity, params object[] Params)
        {
            Log4NetException excp = getExceptioObj(ref Params);

            if (Params != null)
            {
                Logger(cfgLogger, enSeverity, GetParams(Params), excp);
            }
            else
            {
                Logger(cfgLogger, enSeverity, null, excp);
            }
        }
Exemple #4
0
        public static void WriteFatalError(string sFormat, params object[] Params)
        {
            Log4NetException excp = getExceptioObj(ref Params);

            try
            {
                string message = System.String.Format(sFormat, Params);
                Logger(cfgLogger, Log.Severity.FATAL_ERROR, message, excp);
            }
            catch
            {
                Logger(cfgLogger, Log.Severity.FATAL_ERROR, "WriteFatalError -" + sFormat, excp);
            }
        }
Exemple #5
0
        public static void WriteWarning(string sFormat, params object[] Params)
        {
            Log4NetException excp = getExceptioObj(ref Params);

            try
            {
                string message = System.String.Format(sFormat, Params);
                Logger(cfgLogger, Log.Severity.WARNING, message, excp);
            }
            catch
            {
                Logger(cfgLogger, Log.Severity.WARNING, "WriteWarning - " + sFormat, excp);
            }
        }
Exemple #6
0
        public static void WriteDebug(string sFormat, params object[] Params)
        {
            try
            {
                string           message = System.String.Format(sFormat, Params);
                Log4NetException excp    = getExceptioObj(ref Params);

                Logger(cfgLogger, Log.Severity.DEBUG, message, excp);
            }
            catch (Exception e)
            {
                Logger(cfgLogger, Log.Severity.DEBUG, "WriteDebug -", new Log4NetException(e.Message, e));
            }
        }
Exemple #7
0
        public static void Write(Severity enSeverity, System.Reflection.MethodBase oMethod, string sFormat, params object[] Params)
        {
            try
            {
                Type   declaringType = oMethod.DeclaringType;
                string sTypeName     = declaringType.Name;
                string sMethodName   = oMethod.Name;
                string tempStr       = Params != null?string.Format(sFormat, Params) : string.Empty;

                string message = string.Format("{0}.{1}:{2}", sTypeName, sMethodName, tempStr);

                Log4NetException excp = getExceptioObj(ref Params);

                Logger(cfgLogger, enSeverity, message, excp);
            }
            catch
            {
                Logger(cfgLogger, enSeverity,
                       string.Format("Log.Write - {0}.{1}:{2}", oMethod.DeclaringType.Name, oMethod.Name),
                       null);
            }
        }
Exemple #8
0
        private static Log4NetException GetTISException(StackFrame frame, string message = "")
        {
            if (frame == null)
            {
                return(null);
            }

            try
            {
                MethodBase       method = frame.GetMethod();
                Log4NetException excp   = new Log4NetException(message);
                excp.Source       = method.Module.Name;
                excp.m_Class      = method.DeclaringType.ToString();
                excp.m_Method     = method.Name;
                excp.m_StackTrace = frame.ToString();
                return(excp);
            }
            catch
            {
                return(null);
            }
        }
Exemple #9
0
        private static string GetParams(params object[] Params)
        {
            Log4NetException excepObj = new Log4NetException();
            var obj1 = excepObj.GetType();

            if ((Params == null) || (Params.Length <= 0))
            {
                return(string.Empty);
            }

            StringBuilder oMsg = new StringBuilder();

            foreach (object oParam in Params)
            {
                if (oParam != null)
                {
                    var obj2 = oParam.GetType();
                    if (obj1.IsAssignableFrom(obj2))
                    {
                        continue;// oMsg.Append((oParam as Exception).Message);
                    }
                    else
                    {
                        oMsg.Append(oParam.ToString());
                    }
                }
                else
                {
                    oMsg.Append("(null)");
                }

                oMsg.Append(" ");
            }

            return(oMsg.ToString());
        }
Exemple #10
0
        /// <summary>
        /// Logs an entry to the specified log.
        /// </summary>
        /// <param name="logName">The name of the log.</param>
        /// <param name="loggingLevel">The Severity level.</param>
        /// <param name="message">The message.</param>
        /// <param name="exception">Any exception to be logged.</param>
        /// <exception cref="InvalidLogException">Thrown if <paramref name="logName"/> does not exist.</exception>
        ///
        public static void Logger(string logName, Severity loggingLevel, string message, Log4NetException excp)
        {
            Initialize(LogPath, logName);

            ILog log = LogManager.GetLogger(logName);

            if (log != null)
            {
                LogBase(log, loggingLevel, message, excp);
                //Flush the message queue...
                try
                {
                    for (int indx = 0; indx < waitingLst.Count; indx++)
                    {
                        logItem qItem = (logItem)waitingLst.Dequeue();
                        LogBase(log, qItem.loggingLevel, qItem.message, qItem.obj as Log4NetException);
                    }
                    waitingLst.Clear();
                }
                catch
                {
                    if (waitingLst != null)
                    {
                        waitingLst.Clear();
                    }
                }
            }
        }