Esempio n. 1
0
        /// <summary>
        /// 디버그 로깅.
        /// </summary>
        /// <param name="sourceType">Source 타입</param>
        /// <param name="data">LogData 개체. null이 아닐 경우, 포함된 DataStack 정보를 기록함.</param>
        public static void WriteDebug(LogSourceType sourceType, LogData data)
        {
            // 로깅 사용하지 않을 경우 종료
            if (!_enableLog)
            {
                return;
            }
            if (!_enableDebugLog)
            {
                return;
            }

            // StackTrace 원본이 LogManager일 경우 종료
            if (CalledBySelf())
            {
                return;
            }

            try
            {
                // 필드값 생성
                List <SqlParameter> values = CreateDefaultParameters(sourceType, LogType.Debug, data);

                // DB에 쓰기
                InsertIntoDatabase(values);
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵
        }
Esempio n. 2
0
        /// <summary>
        /// 오류 로깅.
        /// </summary>
        /// <param name="sourceType">Source 타입</param>
        /// <param name="ex">Exception 개체</param>
        public static void WriteError(LogSourceType sourceType, Exception ex)
        {
            // 로깅 사용하지 않을 경우 종료
            if (!_enableLog)
            {
                return;
            }

            // StackTrace 원본이 LogManager일 경우 종료
            if (CalledBySelf())
            {
                return;
            }

            try
            {
                string message = ex.Message;

                StringBuilder description = new StringBuilder(1024);
                GatherExceptionDescription(ref description, ex, 0);

                // 필드값 생성
                List <SqlParameter> values = CreateDefaultParameters(sourceType, LogType.Error, message, description.ToString());

                // DB에 쓰기
                InsertIntoDatabase(values);
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵
        }
Esempio n. 3
0
 public static void Write(LogSourceType sourceType, uint triggerId, string title, IEnumerable <LogAttribute> attributes, List <LogHelperEntry> referenceEntries, Action <LogEntryRecord> setRecord)
 {
     /*   TaskQueue.AddMessage(() =>
      *                          {
      *                              if (!TitleIds.ContainsKey(title))
      *                              {
      *                                  CreateAndAddNewTitle(title);
      *                              }
      *
      *                              var newLog = Save(sourceType, triggerId, title);
      *                              foreach (var referenceEntry in referenceEntries)
      *                              {
      *                                  if (referenceEntry.Record == null)
      *                                  {
      *                                      LogUtil.WarnException("Log reference entries must be saved before this entry. Type : "+ title);
      *                                      continue;
      *                                  }
      *                                  CreateAndSaveNewLogRef(newLog, referenceEntry);
      *                              }
      *                              setRecord(newLog);
      *                              foreach (var attr in attributes)
      *                              {
      *                                  WriteAttribute(attr, newLog.Id);
      *                              }
      *                          });*/
 }
Esempio n. 4
0
        /// <summary>
        /// 경고 메시지 로깅.
        /// </summary>
        /// <param name="sourceType">Source 타입</param>
        /// <param name="message">메시지</param>
        /// <param name="description">상세 정보. 없을 경우, null.</param>
        public static void WriteWarning(LogSourceType sourceType, string message, string description)
        {
            // 로깅 사용하지 않을 경우 종료
            if (!_enableLog)
            {
                return;
            }
            if (!_enableWarningLog)
            {
                return;
            }

            // StackTrace 원본이 LogManager일 경우 종료
            if (CalledBySelf())
            {
                return;
            }

            try
            {
                // 필드값 생성
                List <SqlParameter> values = CreateDefaultParameters(sourceType, LogType.Warning, message, description);

                // DB에 쓰기
                InsertIntoDatabase(values);
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵
        }
Esempio n. 5
0
        public void Log(string message, LogType logType, LogSourceType logSourceType = LogSourceType.Local)
        {
            if (logType != LogType.Suppress)
            {
                try
                {
                    if (logSourceType == LogSourceType.Local)
                    {
                        this.CreateLogFileIfNecessary();

                        var logMessage = $"{DateTime.UtcNow.ToString()} {logType.ToString().ToUpperInvariant()}:\nMessage: {message}";

                        var currentFileContent = File.ReadAllText(this.FilePath);

                        var newFileContent = $"{logMessage}\n\n\n{currentFileContent}";

                        lock (_logWriteActionSyncLock)
                        {
                            using (var fileWriter = File.CreateText(FilePath))
                            {
                                fileWriter.WriteLine(newFileContent);
                            }
                        }
                    }
                    else if (logSourceType == LogSourceType.Remote)
                    {
                        // TODO: Impelement remote logging here (if necessary).
                    }
                }
                catch (Exception ex)
                {
                    this.Log(ex, LogType.Suppress);
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        ///     Writes the specified source.
        /// </summary>
        /// <param name="src">The source.</param>
        /// <param name="msg">The MSG.</param>
        public virtual ILogger Write(LogSourceType src, string msg)
        {
            msg = string.Format(Settings.DefaultMessageFormat, msg);
            var rec = new LogRecord(src, msg);

            return(Write(rec));
        }
Esempio n. 7
0
        /// <summary>
        ///     Writes the msg.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        /// <param name="src">The source.</param>
        protected override void WriteInternal(string msg, LogSourceType src)
        {
            if (Settings.Severity == LogSeverityType.None)
            {
                return;
            }

            ArgumentValidator.AssertNotNull(msg, "msg");
            Action act;

            switch (src)
            {
            case LogSourceType.Warning:
                act = () => Debug.LogWarning(msg);
                break;

            case LogSourceType.Error:
                act = () => Debug.LogError(msg);
                break;

            default:
                if (Settings.Severity == LogSeverityType.Critical)
                {
                    return;
                }
                act = () => Debug.Log(msg);
                break;
            }
            ThreadHelper.Default.CurrentDispatcher.Dispatch(act);
        }
Esempio n. 8
0
        /// <summary>
        /// 로깅. 타입 설정 가능.
        /// </summary>
        /// <param name="sourceType">Source 타입</param>
        /// <param name="logType">로그 타입.</param>
        /// <param name="message">메시지.</param>
        /// <param name="description">상세 정보.</param>
        public static void WriteLog(LogSourceType sourceType, LogType logType, string message, string description)
        {
            // 로깅 사용하지 않을 경우 종료
            if (!_enableLog)
            {
                return;
            }

            // StackTrace 원본이 LogManager일 경우 종료
            if (CalledBySelf())
            {
                return;
            }

            // 로깅 타입에 따라 로깅 사용 여부 확인
            switch (logType)
            {
            case LogType.Debug:
                if (!_enableDebugLog)
                {
                    return;
                }
                break;

            case LogType.Information:
                if (!_enableInformationLog)
                {
                    return;
                }
                break;

            case LogType.Performance:
                if (!_enablePerformanceLog)
                {
                    return;
                }
                break;

            case LogType.Warning:
                if (!_enableWarningLog)
                {
                    return;
                }
                break;
            }

            try
            {
                // 필드값 생성
                List <SqlParameter> values = CreateDefaultParameters(sourceType, logType, message, description);

                // DB에 쓰기
                InsertIntoDatabase(values);
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵
        }
Esempio n. 9
0
        /// <summary>
        ///     Writes the record.
        /// </summary>
        /// <param name="record">The record.</param>
        /// <param name="src">The source.</param>
        protected override void WriteInternal(LogRecord record, LogSourceType src)
        {
            if (Settings.Severity == LogSeverityType.None)
            {
                return;
            }

            ArgumentValidator.AssertNotNull(record, "record");
            WriteInternal(record.ToString(), src);
        }
Esempio n. 10
0
        private static LogEntryRecord Save(LogSourceType sourceType, uint triggerId, string title)
        {
            LogEntryRecord record = LogEntryRecord.CreateRecord();

            record.TitleId       = TitleIds[title];
            record.Timestamp     = DateTime.Now;
            record.TrigererId    = triggerId;
            record.TriggererType = (byte)sourceType;
            record.Save();
            return(record);
        }
Esempio n. 11
0
        private static LogEntryRecord Save(LogSourceType sourceType, uint triggerId, string title)
        {
            var newLog = LogEntryRecord.CreateRecord();

            newLog.TitleId       = TitleIds[title];
            newLog.Timestamp     = DateTime.Now;
            newLog.TrigererId    = triggerId;
            newLog.TriggererType = (byte)sourceType;
            newLog.Save();
            return(newLog);
        }
Esempio n. 12
0
        /// <summary>
        /// Writes the specified source.
        /// </summary>
        /// <param name="src">The source.</param>
        /// <param name="method">The method.</param>
        /// <returns></returns>
        public virtual ILogger Write(LogSourceType src, Delegate method)
        {
            var logger = Write(src, "{0}.{1}()", method.Target
#if !UNITY_WSA
                               , method.Method.Name
#else
                               , method
#endif
                               );

            return(logger);
        }
Esempio n. 13
0
        public void Log(Exception exception, LogType logType, LogSourceType logSourceType = LogSourceType.Local)
        {
            if (logType != LogType.Suppress)
            {
                try
                {
                    if (logSourceType == LogSourceType.Local)
                    {
                        this.CreateLogFileIfNecessary();

                        var exceptionsList = new List <Exception>();

                        if (exception is AggregateException aggregateException)
                        {
                            var flattenException = aggregateException.Flatten();
                            exceptionsList = flattenException.InnerExceptions.ToList();
                        }
                        else
                        {
                            exceptionsList.Add(exception);
                        }

                        foreach (var currentException in exceptionsList)
                        {
                            var logMessage = $"{DateTime.UtcNow.ToString(DefaultDateTimeFormat)} {logType.ToString().ToUpperInvariant()}:" +
                                             $"\nException Message: {currentException.Message}\nStack Trace:\n{currentException.StackTrace}";

                            var currentFileContent = File.ReadAllText(this.FilePath);

                            var newFileContent = $"{logMessage}\n\n\n{currentFileContent}";

                            lock (_logWriteActionSyncLock)
                            {
                                using (var fileWriter = File.CreateText(FilePath))
                                {
                                    fileWriter.WriteLine(newFileContent);
                                }
                            }
                        }
                    }
                    else if (logSourceType == LogSourceType.Remote)
                    {
                        // TODO: Impelement remote logging here (if necessary).
                    }
                }
                catch (Exception ex)
                {
                    this.Log(ex, LogType.Suppress);
                }
            }
        }
Esempio n. 14
0
        private static List <SqlParameter> CreateDefaultParameters(LogSourceType sourceType, LogType logType, LogData data)
        {
            // ProcessInfo에서 추출
            string message     = null;
            string description = null;

            if (data != null)
            {
                message     = data.Description;
                description = data.ValueStack;
            }

            // 필드값 생성
            return(CreateDefaultParameters(sourceType, logType, message, description));
        }
Esempio n. 15
0
        /// <summary>
        /// 성능 로깅.
        /// </summary>
        /// <param name="sourceType">Source 타입</param>
        /// <param name="data">LogData 개체. null일 경우, 로그 남지 않음.</param>
        public static void WritePerformance(LogSourceType sourceType, LogData data)
        {
            // 로깅 사용하지 않을 경우 종료
            if (!_enableLog)
            {
                return;
            }
            if (!_enablePerformanceLog)
            {
                return;
            }

            // StackTrace 원본이 LogManager일 경우 종료
            if (CalledBySelf())
            {
                return;
            }

            try
            {
                // 소요 시간이 컨피그에 정의된 시간보다 같거나 클 경우에만 기록
                // ->  컨피그 정의 시간이 0 이하이면 항상 기록됨
                if (data != null)
                {
                    // 타이머 종료
                    data.StopTimer();

                    if (data.ElapsedMilliseconds >= _performanceMilliseconds)
                    {
                        string message     = data.Description;
                        string description = data.ValueStack;

                        // 필드값 생성
                        List <SqlParameter> values = CreateDefaultParameters(sourceType, LogType.Performance, message, description);
                        values.Add(new SqlParameter("@StartTime", data.StartTime.ToString("yyyy-MM-dd HH:mm:ss.fff")));
                        values.Add(new SqlParameter("@EndTime", data.EndTime.ToString("yyyy-MM-dd HH:mm:ss.fff")));
                        values.Add(new SqlParameter("@ElapsedMilliseconds", data.ElapsedMilliseconds));

                        // DB에 쓰기
                        InsertIntoDatabase(values);
                    }
                }
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵
        }
Esempio n. 16
0
        private static List<SqlParameter> CreateDefaultParameters(LogSourceType sourceType, LogType logType, LogData data)
        {
            // ProcessInfo에서 추출
            string message = null;
            string description = null;
            if (data != null)
            {
                message = data.Description;
                description = data.ValueStack;
            }

            // 필드값 생성
            return CreateDefaultParameters(sourceType, logType, message, description);
        }
Esempio n. 17
0
        /// <summary>
        ///     Writes the specified record.
        /// </summary>
        /// <param name="src">The source type.</param>
        /// <param name="msgFormat">The MSG format.</param>
        /// <param name="args">The arguments.</param>
        public virtual ILogger Write(LogSourceType src, string msgFormat, params object[] args)
        {
            var msg = string.Format(msgFormat, args);

            return(Write(src, msg));
        }
Esempio n. 18
0
 /// <summary>
 ///     Writes the record.
 /// </summary>
 /// <param name="record">The record.</param>
 /// <param name="src">The source.</param>
 protected virtual void WriteInternal(LogRecord record, LogSourceType src)
 {
 }
Esempio n. 19
0
 /// <summary>
 ///     Writes the msg.
 /// </summary>
 /// <param name="msg">The MSG.</param>
 /// <param name="src">The source.</param>
 protected virtual void WriteInternal(string msg, LogSourceType src)
 {
 }
Esempio n. 20
0
 public LogHelperEntry(string title, LogSourceType sourceType, uint triggerId)
 {
     _title      = title;
     _sourceType = sourceType;
     _triggerId  = triggerId;
 }
Esempio n. 21
0
 /// <summary>
 /// ����Ϣ��Ϊָ�����͵����ݴ�����־
 /// </summary>
 /// <param name="message">��Ϣ����</param>
 /// <param name="sourceType">��ϢԴ</param>
 /// <param name="logType">��Ϣ���ͣ��д���һ����Ϣ�����ͨ�������ʧ�ܵ�<seealso cref="EventLogEntryType"/></param>
 public void Write(string message, EventLogEntryType logType, LogSourceType sourceType)
 {
     if (string.IsNullOrEmpty(message))
     {
         throw new ArgumentException("��־���ݲ���Ϊ��.");
     }
     dal.Write(message, logType, sourceType);
 }
Esempio n. 22
0
 public static void Write(LogSourceType sourceType, uint triggerId, string title,
                          IEnumerable <LogAttribute> attributes, List <LogHelperEntry> referenceEntries,
                          Action <LogEntryRecord> setRecord)
 {
 }
Esempio n. 23
0
 /// <summary>
 /// д�����ݿ���־
 /// </summary>
 /// <param name="message">д�����Ϣ</param>
 /// <param name="sourceType">��־Դ</param>
 /// <returns>��־��¼����</returns>
 public string Write(string message, LogSourceType sourceType)
 {
     return Write(message, EventLogEntryType.Error, sourceType);
 }
Esempio n. 24
0
        /// <summary>
        /// 경고 메시지 로깅.
        /// </summary>
        /// <param name="sourceType">Source 타입</param>
        /// <param name="data">LogData 개체. null이 아닐 경우, 포함된 DataStack 정보를 기록함.</param>
        public static void WriteWarning(LogSourceType sourceType, LogData data)
        {
            // 로깅 사용하지 않을 경우 종료
            if (!_enableLog) return;
            if (!_enableWarningLog) return;

            // StackTrace 원본이 LogManager일 경우 종료
            if (CalledBySelf()) return;

            try
            {
                // 필드값 생성
                List<SqlParameter> values = CreateDefaultParameters(sourceType, LogType.Warning, data);

                // DB에 쓰기
                InsertIntoDatabase(values);
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵
        }
Esempio n. 25
0
        /// <summary>
        /// 성능 로깅.
        /// </summary>
        /// <param name="sourceType">Source 타입</param>
        /// <param name="data">LogData 개체. null일 경우, 로그 남지 않음.</param>
        public static void WritePerformance(LogSourceType sourceType, LogData data)
        {
            // 로깅 사용하지 않을 경우 종료
            if (!_enableLog) return;
            if (!_enablePerformanceLog) return;

            // StackTrace 원본이 LogManager일 경우 종료
            if (CalledBySelf()) return;

            try
            {
                // 소요 시간이 컨피그에 정의된 시간보다 같거나 클 경우에만 기록
                // ->  컨피그 정의 시간이 0 이하이면 항상 기록됨
                if (data != null)
                {
                    // 타이머 종료
                    data.StopTimer();

                    if (data.ElapsedMilliseconds >= _performanceMilliseconds)
                    {
                        string message = data.Description;
                        string description = data.ValueStack;

                        // 필드값 생성
                        List<SqlParameter> values = CreateDefaultParameters(sourceType, LogType.Performance, message, description);
                        values.Add(new SqlParameter("@StartTime", data.StartTime.ToString("yyyy-MM-dd HH:mm:ss.fff")));
                        values.Add(new SqlParameter("@EndTime", data.EndTime.ToString("yyyy-MM-dd HH:mm:ss.fff")));
                        values.Add(new SqlParameter("@ElapsedMilliseconds", data.ElapsedMilliseconds));

                        // DB에 쓰기
                        InsertIntoDatabase(values);
                    }
                }
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵
        }
Esempio n. 26
0
        /// <summary>
        /// 메시지 로깅.
        /// </summary>
        /// <param name="sourceType">Source 타입</param>
        /// <param name="message">메시지</param>
        /// <param name="message">상세 정보. 없을 경우, null.</param>
        public static void WriteInformation(LogSourceType sourceType, string message, string description)
        {
            // 로깅 사용하지 않을 경우 종료
            if (!_enableLog) return;
            if (!_enableInformationLog) return;

            // StackTrace 원본이 LogManager일 경우 종료
            if (CalledBySelf()) return;

            try
            {
                // 필드값 생성
                List<SqlParameter> values = CreateDefaultParameters(sourceType, LogType.Information, message, description);

                // DB에 쓰기
                InsertIntoDatabase(values);
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵
        }
Esempio n. 27
0
        /// <summary>
        /// 오류 로깅.
        /// </summary>
        /// <param name="sourceType">Source 타입</param>
        /// <param name="ex">Exception 개체</param>
        public static void WriteError(LogSourceType sourceType, Exception ex)
        {
            // 로깅 사용하지 않을 경우 종료
            if (!_enableLog) return;

            // StackTrace 원본이 LogManager일 경우 종료
            if (CalledBySelf()) return;

            try
            {
                string message = ex.Message;

                StringBuilder description = new StringBuilder(1024);
                GatherExceptionDescription(ref description, ex, 0);

                // 필드값 생성
                List<SqlParameter> values = CreateDefaultParameters(sourceType, LogType.Error, message, description.ToString());

                // DB에 쓰기
                InsertIntoDatabase(values);
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵
        }
Esempio n. 28
0
        /// <summary>
        /// д�����ݿ���־
        /// </summary>
        /// <param name="message">д�����Ϣ</param>
        /// <param name="logType">��־����,��Ϣ,����,����,��֤ͨ����</param>
        /// <param name="sourceType">��־Դ</param>
        /// <returns>��־��¼����</returns>
        public string Write(string message, EventLogEntryType logType, LogSourceType sourceType)
        {
            string typeID = EnumHandler<EventLogEntryType>.GetStringFromEnum(logType);
            string sourceID = EnumHandler<LogSourceType>.GetStringFromEnum(sourceType);

            string sql = @"INSERT INTO [Log]
                                           ([Message]
                                           ,[Type]
                                           ,[SourceID])
                                     VALUES
                                           (@Message
                                           ,@Type
                                           ,@SourceID)";
            SqlParameter[] param = new SqlParameter[3];
            param[0] = new SqlParameter("@Message", message);
            param[1] = new SqlParameter("@Type", typeID);
            param[2] = new SqlParameter("@SourceID", sourceID);
            string result = Convert.ToString(SqlHelper.ExecuteScalar(DBConnection.ConnectionString, CommandType.Text, sql, param));
            return result;
        }
Esempio n. 29
0
 public static LogHelperEntry Create(string title, LogSourceType sourceType, uint triggerId)
 {
     return(new LogHelperEntry(title, sourceType, triggerId));
 }
Esempio n. 30
0
        private static List<SqlParameter> CreateDefaultParameters(LogSourceType sourceType, LogType logType, string message, string detail)
        {
            List<SqlParameter> values = new List<SqlParameter>();

            // 로그 타입
            try
            {
                values.Add(new SqlParameter("@LogType", logType.ToString().Substring(0, 1)));
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵

            // 로그 소스 타입
            try
            {
                values.Add(new SqlParameter("@LogSourceType", sourceType.ToString()));
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵

            // 요청자 정보 : 자동
            try
            {
                // 웹 요청인 경우, 요청자 정보 자동 설정
                if (HttpContext.Current != null)
                {
                    values.Add(new SqlParameter("@RequestIP", HttpContext.Current.Request.UserHostAddress));
                    values.Add(new SqlParameter("@RequestUser", HttpContext.Current.User.Identity.Name));
                    values.Add(new SqlParameter("@RequestUrl", HttpContext.Current.Request.Url.ToString()));

                    //VpdUserInfo userInfo = VpdUserInfo.GetCurrentUserInfo();
                    //if (userInfo != null)
                    //{
                    //    values.Add(new SqlParameter("@RequestUserName", userInfo.UserName));
                    //}
                }
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵

            // 어셈블리 정보 : 자동
            try
            {
                // 호출 메소드 정보 찾기
                MethodBase callerMethod = null;
                Type callerType = null;

                // 호출 스택에서 역순으로 찾는다.
                // - 현재 네임 스페이스(첫번째 호출 스택)와 동일한 네임 스페이스에 포함된 프레임은 제외한다.

                StackTrace st = new StackTrace();
                string currentNamespace = st.GetFrame(0).GetMethod().DeclaringType.Namespace;

                for (int i = 1; i < st.FrameCount; i++)
                {
                    callerMethod = st.GetFrame(i).GetMethod();
                    callerType = callerMethod.DeclaringType;

                    // 현재 네임 스페이스와 동일한 네임 스페이스에 포함된 프레임은 제외한다.
                    if (callerMethod.DeclaringType.Namespace == currentNamespace) continue;

                    // 가장 최하위 호출 메소드 찾음
                    break;
                }

                // 호출 모듈 정보
                values.Add(new SqlParameter("@AssemblyName", callerType.Assembly.FullName));
                values.Add(new SqlParameter("@Namespace", callerType.Namespace));
                values.Add(new SqlParameter("@ClassName", callerType.Name));
                values.Add(new SqlParameter("@MethodName", callerMethod.Name));

                // * message가 생략된 경우, message에 '클래스명.메소드명'을 넣는다.
                if (string.IsNullOrEmpty(message))
                {
                    message = string.Format("{0}.{1}", callerType.Name, callerMethod.Name);
                }
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵

            // 수행 머신 정보 : 자동
            try
            {
                values.Add(new SqlParameter("@ServerMachine", System.Environment.MachineName));
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵

            // 로그 메시지
            values.Add(new SqlParameter("@LogMessage", message));
            values.Add(new SqlParameter("@LogDetail", detail));

            return values;
        }
Esempio n. 31
0
        /// <summary>
        /// 로깅. 타입 설정 가능.
        /// </summary>
        /// <param name="sourceType">Source 타입</param>
        /// <param name="logType">로그 타입.</param>
        /// <param name="message">메시지.</param>
        /// <param name="description">상세 정보.</param>
        public static void WriteLog(LogSourceType sourceType, LogType logType, string message, string description)
        {
            // 로깅 사용하지 않을 경우 종료
            if (!_enableLog) return;

            // StackTrace 원본이 LogManager일 경우 종료
            if (CalledBySelf()) return;

            // 로깅 타입에 따라 로깅 사용 여부 확인
            switch (logType)
            {
                case LogType.Debug:
                    if (!_enableDebugLog) return;
                    break;
                case LogType.Information:
                    if (!_enableInformationLog) return;
                    break;
                case LogType.Performance:
                    if (!_enablePerformanceLog) return;
                    break;
                case LogType.Warning:
                    if (!_enableWarningLog) return;
                    break;
            }

            try
            {
                // 필드값 생성
                List<SqlParameter> values = CreateDefaultParameters(sourceType, logType, message, description);

                // DB에 쓰기
                InsertIntoDatabase(values);
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵
        }
Esempio n. 32
0
        private static List <SqlParameter> CreateDefaultParameters(LogSourceType sourceType, LogType logType, string message, string detail)
        {
            List <SqlParameter> values = new List <SqlParameter>();

            // 로그 타입
            try
            {
                values.Add(new SqlParameter("@LogType", logType.ToString().Substring(0, 1)));
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵

            // 로그 소스 타입
            try
            {
                values.Add(new SqlParameter("@LogSourceType", sourceType.ToString()));
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵

            // 요청자 정보 : 자동
            try
            {
                // 웹 요청인 경우, 요청자 정보 자동 설정
                if (HttpContext.Current != null)
                {
                    values.Add(new SqlParameter("@RequestIP", HttpContext.Current.Request.UserHostAddress));
                    values.Add(new SqlParameter("@RequestUser", HttpContext.Current.User.Identity.Name));
                    values.Add(new SqlParameter("@RequestUrl", HttpContext.Current.Request.Url.ToString()));

                    //VpdUserInfo userInfo = VpdUserInfo.GetCurrentUserInfo();
                    //if (userInfo != null)
                    //{
                    //    values.Add(new SqlParameter("@RequestUserName", userInfo.UserName));
                    //}
                }
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵

            // 어셈블리 정보 : 자동
            try
            {
                // 호출 메소드 정보 찾기
                MethodBase callerMethod = null;
                Type       callerType   = null;

                // 호출 스택에서 역순으로 찾는다.
                // - 현재 네임 스페이스(첫번째 호출 스택)와 동일한 네임 스페이스에 포함된 프레임은 제외한다.

                StackTrace st = new StackTrace();
                string     currentNamespace = st.GetFrame(0).GetMethod().DeclaringType.Namespace;

                for (int i = 1; i < st.FrameCount; i++)
                {
                    callerMethod = st.GetFrame(i).GetMethod();
                    callerType   = callerMethod.DeclaringType;

                    // 현재 네임 스페이스와 동일한 네임 스페이스에 포함된 프레임은 제외한다.
                    if (callerMethod.DeclaringType.Namespace == currentNamespace)
                    {
                        continue;
                    }

                    // 가장 최하위 호출 메소드 찾음
                    break;
                }

                // 호출 모듈 정보
                values.Add(new SqlParameter("@AssemblyName", callerType.Assembly.FullName));
                values.Add(new SqlParameter("@Namespace", callerType.Namespace));
                values.Add(new SqlParameter("@ClassName", callerType.Name));
                values.Add(new SqlParameter("@MethodName", callerMethod.Name));

                // * message가 생략된 경우, message에 '클래스명.메소드명'을 넣는다.
                if (string.IsNullOrEmpty(message))
                {
                    message = string.Format("{0}.{1}", callerType.Name, callerMethod.Name);
                }
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵

            // 수행 머신 정보 : 자동
            try
            {
                values.Add(new SqlParameter("@ServerMachine", System.Environment.MachineName));
            }
            catch { }   // 로깅 시 예외 발생은 무조건 스킵

            // 로그 메시지
            values.Add(new SqlParameter("@LogMessage", message));
            values.Add(new SqlParameter("@LogDetail", detail));

            return(values);
        }