コード例 #1
0
 public static void WriteInformationLog(string message, string _namespace, out LogMessageWLevel userLog, out DebugLogMessageLevel debugLog, bool includeDateTime = true, params string[] additionalMessages)
 {
     userLog  = null;
     debugLog = null;
     if (LogWriter != null)
     {
         try
         {
             LogWriter.WriteInformationLog(message, _namespace, out userLog, out debugLog, includeDateTime, additionalMessages);
         }
         catch
         {
             if (Helper.ShowMessageBox(MessageBoxStrings.Logger.LOG_NOT_ABLE_CHOICE, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
             {
                 LogWriter = null;
             }
         }
     }
     if (debugLog != null)
     {
         logList.Logs.Add(debugLog);
         if (OnLogMessageCreated != null)
         {
             OnLogMessageCreated(debugLog);
         }
     }
 }
コード例 #2
0
 public static void CloseLog()
 {
     if (LogWriter != null)
     {
         LogWriter.Dispose();
         LogWriter = null;
     }
 }
コード例 #3
0
        public static void InitializeLogger()
        {
            Exception ex;
            string    _namespace = MethodBase.GetCurrentMethod().ToLogFormatFullName();

            if (!Directory.Exists(PMFileSystem.LogDebug_Dir))
            {
                if (Helper.CreateFolderSafely(PMFileSystem.LogDebug_Dir, _namespace, out ex) == CreateFolderResult.UserCancelled)
                {
                    Helper.ShowMessageBox(MessageBoxStrings.Logger.DEBUG_DIR_NOT_ABLE, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            if (!Directory.Exists(PMFileSystem.LogUser_Dir))
            {
                if (Helper.CreateFolderSafely(PMFileSystem.LogUser_Dir, _namespace, out ex) == CreateFolderResult.UserCancelled) // null arg
                {
                    Helper.ShowMessageBox(MessageBoxStrings.Logger.USER_DIR_NOT_ABLE, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            Exception exCatched = null;

            try
            {
                BasicLoggingTools.LimitLogsInFolder(PMFileSystem.LogDebug_Dir, Properties.Settings.Default.LogLimit, Properties.Settings.Default.LogLimitType.ToBasicLogLimit());
                BasicLoggingTools.LimitLogsInFolder(PMFileSystem.LogUser_Dir, Properties.Settings.Default.LogLimit, Properties.Settings.Default.LogLimitType.ToBasicLogLimit());
            }
            catch (Exception exCaught)
            {
                exCatched = exCaught;
            }

            try
            {
                LogWriter = new BasicLogCombo(PMFileSystem.LogUser_Dir, PMFileSystem.LogDebug_Dir);
            }
            catch
            {
                Helper.ShowMessageBox(MessageBoxStrings.Logger.LOG_NOT_ABLE, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                LogWriter = null;
            }
            if (exCatched != null)
            {
                Helper.ShowMessageBox(MessageBoxStrings.Logger.LIMIT_NOT_ABLE, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                WriteErrorLog(exCatched.Message, MethodBase.GetCurrentMethod().ToLogFormatFullName(), exCatched, BasicDebugLogger.DebugErrorType.Error);
            }
        }