Exemplo n.º 1
0
        /// <summary>
        /// Transform Exception in <see cref="master.framework.dto.DataLogging"/>
        /// </summary>
        /// <param name="obj">Exception</param>
        /// <returns><see cref="master.framework.dto.DataLogging"/></returns>
        public static dto.DataLogging ToDataLogging(this Exception obj)
        {
            dto.DataLogging ret   = new dto.DataLogging();
            var             aux   = obj;
            int             count = 0;

            while (aux != null)
            {
                ret.Message    += (string.IsNullOrWhiteSpace(ret.Message) ? "" : " ") + aux.Message;
                ret.StackTrace += count.ToString() + ": " + aux.StackTrace;
                ret.Source     += count.ToString() + ": " + aux.Source;

                aux = aux.InnerException;
                count++;
            }
            return(ret);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Call record log
        /// </summary>
        /// <param name="logType"></param>
        /// <param name="classType"></param>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        /// <param name="methodName"></param>
        /// <param name="lineNumber"></param>
        private static void log(Enumerators.LogType logType, object classType, string message = null, Exception ex = null, string methodName = null, int lineNumber = 0)
        {
            string errorMsg  = string.Empty;
            string recordMsg = ".{0} at line number: {1} with message: {2} {3}";

            setLogger(classType.GetType());
            if (ex != null)
            {
                dto.DataLogging dl = ex?.ToDataLogging();
                if (dl != null)
                {
                    errorMsg = string.Format("- |-| - Exception Source: {0} -- Message: {1} -- StackTrace: {2}", dl.Source, dl.Message, dl.StackTrace);
                }
            }

            recordMsg = string.Format(recordMsg, methodName, lineNumber, string.IsNullOrWhiteSpace(message) ? "-" : message, errorMsg);

            switch (logType)
            {
            case Enumerators.LogType.Debug:
                logger.Debug(recordMsg);
                break;

            case Enumerators.LogType.Info:
                logger.Info(recordMsg);
                break;

            case Enumerators.LogType.Warn:
                logger.Warn(recordMsg);
                break;

            case Enumerators.LogType.Fatal:
                logger.Fatal(recordMsg);
                break;

            case Enumerators.LogType.Error:
                logger.Error(recordMsg);
                break;
            }
        }