Centreon_EventLog_2_Syslog.Debug.rotateFile C# (CSharp) 메소드

rotateFile() 개인적인 메소드

Make rotation of debug file
private rotateFile ( ) : void
리턴 void
        private void rotateFile()
        {
            String[] files = Directory.GetFiles(this._Path);

            // Count available debug files
            int nbDebufFile = 0;
            foreach (String file in files)
            {
                Regex re = new Regex(@"Debug.log", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);

                if (re.IsMatch(file))
                {
                    nbDebufFile++;
                }
            }

            // Delete old debug file
            if (nbDebufFile >= this._DebugInfo.FileNumber)
            {
                foreach (String file in files)
                {
                    String pattern = "Debug.log.";
                    String fileNumber = file.Substring(file.LastIndexOf(pattern) + pattern.Length, 1);
                    int ifileNumber = 0;

                    try
                    {
                        ifileNumber = Convert.ToInt32(fileNumber);
                        if (ifileNumber >= this._DebugInfo.FileNumber)
                        {
                            File.Delete(file);
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }
            }

            for (int i = nbDebufFile; i > 1; i--)
            {
                try
                {
                    File.Move(this._Path + "\\Debug.log." + (i - 1), this._Path + "\\Debug.log." + i);
                }
                catch (Exception e)
                {
                }
            }

            try
            {
                File.Move(this._Path + "\\Debug.log", this._Path + "\\Debug.log.1");
            }
            catch (Exception e)
            {
            }
        }