Example #1
0
 private void ValidateLogFileLocationEnumValue(LogFileLocation value, string paramName)
 {
     if ((value < LogFileLocation.TempDirectory) || (value > LogFileLocation.Custom))
     {
         throw new InvalidEnumArgumentException(paramName, (int) value, typeof(LogFileLocation));
     }
 }
Example #2
0
 public FileLogTraceListener(string name) : base(name)
 {
     this.m_Location = LogFileLocation.LocalUserApplicationDirectory;
     this.m_AutoFlush = false;
     this.m_Append = true;
     this.m_IncludeHostName = false;
     this.m_DiskSpaceExhaustedBehavior = DiskSpaceExhaustedOption.DiscardMessages;
     this.m_BaseFileName = Path.GetFileNameWithoutExtension(Application.ExecutablePath);
     this.m_LogFileDateStamp = LogFileCreationScheduleOption.None;
     this.m_MaxFileSize = 0x4c4b40L;
     this.m_ReserveDiskSpace = 0x989680L;
     this.m_Delimiter = "\t";
     this.m_Encoding = System.Text.Encoding.UTF8;
     this.m_CustomLocation = Application.UserAppDataPath;
     this.m_Day = DateAndTime.Now.Date;
     this.m_FirstDayOfWeek = GetFirstDayOfWeek(DateAndTime.Now.Date);
     this.m_PropertiesSet = new BitArray(12, false);
     this.m_SupportedAttributes = new string[] { 
         "append", "Append", "autoflush", "AutoFlush", "autoFlush", "basefilename", "BaseFilename", "baseFilename", "BaseFileName", "baseFileName", "customlocation", "CustomLocation", "customLocation", "delimiter", "Delimiter", "diskspaceexhaustedbehavior", 
         "DiskSpaceExhaustedBehavior", "diskSpaceExhaustedBehavior", "encoding", "Encoding", "includehostname", "IncludeHostName", "includeHostName", "location", "Location", "logfilecreationschedule", "LogFileCreationSchedule", "logFileCreationSchedule", "maxfilesize", "MaxFileSize", "maxFileSize", "reservediskspace", 
         "ReserveDiskSpace", "reserveDiskSpace"
      };
 }
Example #3
0
        private void UpdateLogFileList(string selectedDirectoryTitle = null)
        {
            if (selectedDirectoryTitle == null)
            {
                selectedDirectoryTitle = _selectedDirectoryTitle;
            }
            else
            {
                _selectedDirectoryTitle = selectedDirectoryTitle;
            }

            string errorSearchTerm;
            string warningSearchTerm;

            // remember user selection
            string selectedIndexValue = null;
            int    selectedIndex      = -1;

            selectedIndex = listBoxViewLogFiles.SelectedIndex;
            if (selectedIndex >= 0)
            {
                selectedIndexValue = listBoxViewLogFiles.SelectedItems[0].ToString();
            }

            switch (selectedDirectoryTitle)
            {
            case "SnapRAID Scheduled Jobs":
                // SnapRAID Scheduled Jobs
                errorSearchTerm        = _snapraidErrorSearchTerm;
                warningSearchTerm      = _snapraidWarningSearchTerm;
                LexerToUse             = LexerNameEnum.ScanRaid;
                _logSourcePath         = $@"{Path.GetDirectoryName(Properties.Settings.Default.ConfigFileLocation)}\{Properties.Settings.Default.LogFileDirectory}\";
                _logFileWatcher.Path   = $@"{Path.GetDirectoryName(Properties.Settings.Default.ConfigFileLocation)}\{Properties.Settings.Default.LogFileDirectory}\";
                _logFileWatcher.Filter = "*.log";
                _logFileWatcher.EnableRaisingEvents = true;
                break;

            case "Elucidate":
                // Elucidate
                errorSearchTerm        = _elucidateErrorSearchTerm;
                warningSearchTerm      = _elucidateWarningSearchTerm;
                LexerToUse             = LexerNameEnum.NLog;
                _logSourcePath         = LogFileLocation.GetActiveLogFileLocation();
                _logFileWatcher.Path   = LogFileLocation.GetActiveLogFileLocation();
                _logFileWatcher.Filter = "*.log";
                _logFileWatcher.EnableRaisingEvents = true;
                break;

            default:
                _logFileWatcher.EnableRaisingEvents = false;
                return;
            }

            Log.Instance.Debug($"_logSourcePath : {_logSourcePath}");

            listBoxViewLogFiles.Items.Clear();

            if (!Directory.Exists(_logSourcePath))
            {
                return;
            }

            DirectoryInfo logFileDirectoryInfo = new DirectoryInfo(_logSourcePath);

            List <FileInfo> allLogs = logFileDirectoryInfo.GetFiles("*.log").OrderByDescending(a => a.Name).ToList();

            List <FileInfo> filteredLogs = new List <FileInfo>();

            if (checkedFilesWithError.Checked)
            {
                IEnumerable <FileInfo> filesWithErrors = from file in allLogs
                                                         let fileText = GetFileText(file.FullName)
                                                                        where fileText.Contains(errorSearchTerm)
                                                                        select file;
                filteredLogs = filteredLogs.Union(filesWithErrors).ToList();
            }

            if (checkedFilesWithWarn.Checked)
            {
                IEnumerable <FileInfo> filesWithWarnings = from file in allLogs
                                                           let fileText = GetFileText(file.FullName)
                                                                          where fileText.Contains(warningSearchTerm)
                                                                          select file;
                filteredLogs = filteredLogs.Union(filesWithWarnings).ToList();
            }

            List <FileInfo> logsToShow = filteredLogs.Count > 0 ? filteredLogs : allLogs;

            logsToShow = logsToShow.OrderByDescending(a => a.Name).ToList();
            foreach (FileInfo log in logsToShow)
            {
                listBoxViewLogFiles.Items.Add(log.Name);
            }

            // restore user selection, if it stil lexists
            if (selectedIndex >= 0 && !string.IsNullOrEmpty(selectedIndexValue))
            {
                int indexFound = -1;
                indexFound = listBoxViewLogFiles.FindStringExact(selectedIndexValue);
                if (indexFound >= 0)
                {
                    listBoxViewLogFiles.SelectedIndex = indexFound;
                }
            }
        }