Esempio n. 1
0
        /// <summary>
        /// Change le fichier logger.ini pour activer les traces
        /// </summary>
        /// <returns></returns>
        ///

        /*
         *      public static bool ActivateLog()
         *      {
         *              bool success = false;
         *              try
         *              {
         *                      string root = EConf.EConfPlayer.Instance.GetEconfRoot();
         *                      if(root==null || root==string.Empty)
         *                      {
         *                              return false;
         *                      }
         *                      root = root.Trim();
         *                      if(root!=null && root!=string.Empty)
         *                      {
         *                              if(!root.EndsWith(@"\"))
         *                              {
         *                                      root = root+@"\";
         *                              }
         *                              System.IO.Stream strLogg =  System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ModuleTest."+ConfigManager.DirectoryResources+"."+ConfigManager.ActiveLoggerIni);
         *                              if(strLogg!=null)
         *                              {
         *                                      Tools.File.CopyFromStream(strLogg,root+ConfigManager.LoggerIni);
         *                              }
         *                      }
         *                      success = true;
         *                      _IsLogActivated = true;
         *              }
         *              catch(Exception exception)
         *              {
         *                      Tools.Trace.WriteLine("Impossible de mettre à jour le fichier logger :"+exception.ToString());
         *                      success = false;
         *              }
         *              return success;
         *      }
         *
         *      /// <summary>
         *      /// Change le fichier logger.ini pour désactiver les traces
         *      /// </summary>
         *      /// <returns></returns>
         *      public static bool DesactivateLog()
         *      {
         *              bool success = false;
         *              try
         *              {
         *                      string root = EConf.EConfPlayer.Instance.GetEconfRoot();
         *                      root = root.Trim();
         *                      if(root!=null && root!=string.Empty)
         *                      {
         *                              if(!root.EndsWith(@"\"))
         *                              {
         *                                      root = root+@"\";
         *                              }
         *                              System.IO.Stream strLogg = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ModuleTest."+ConfigManager.DirectoryResources+"."+ConfigManager.InactiveLoggerIni);
         *                              if(strLogg!=null)
         *                              {
         *                                      Tools.File.CopyFromStream(strLogg,root+ConfigManager.LoggerIni);
         *                              }
         *                      }
         *                      success = true;
         *                      _IsLogActivated = false;
         *              }
         *              catch(Exception exception)
         *              {
         *                      Tools.Trace.WriteLine("Impossible de mettre à jour le fichier logger :"+exception.ToString());
         *                      success = false;
         *              }
         *              return success;
         *      } */
        /// <summary>
        /// Démarre l'enregistrement des logs. Prends la taille du fichier de log
        /// </summary>
        /// <returns></returns>
        public static bool StartSessionLog()
        {
            bool success = false;

            if (!_IsLogActivated)
            {
                return(false);
            }
            if (_Instance == null)
            {
                _Instance = new FTPlayer();
            }
            if (!System.IO.File.Exists(LogPath))
            {
                return(false);
            }
            try
            {
                System.IO.FileInfo fileInfo = new System.IO.FileInfo(LogPath);
                _Instance._InitFileSize = fileInfo.Length;
                success = true;
            }
            catch (Exception exception)
            {
                Tools.Trace.WriteLine(exception);
            }
            return(success);
        }
Esempio n. 2
0
        /// <summary>
        /// Termine la session de logs
        /// </summary>
        /// <param name="errorCountDurungSession"></param>
        /// <param name="lineLog"></param>
        /// <returns></returns>
        public static bool EndSessionLog(out int errorCountDurungSession, out string lineLog)
        {
            System.IO.FileStream stream = null;
            double result  = 0;
            bool   success = false;

            errorCountDurungSession = 0;
            lineLog = string.Empty;
            if (!_IsLogActivated)
            {
                return(false);
            }
            if (_Instance == null)
            {
                _Instance = new FTPlayer();
            }
            if (!System.IO.File.Exists(LogPath))
            {
                return(false);
            }
            try
            {
                EconfTools.QueryPerfCounter.Instance.Start();
                System.IO.File.Copy(LogPath, @"c:\temp.txt", true);
                EconfTools.QueryPerfCounter.Instance.Stop();
                result = EconfTools.QueryPerfCounter.Instance.Duration();
                Tools.Trace.WriteLog("EndSessionLog copy fichier :" + result + " nanos");

                EconfTools.QueryPerfCounter.Instance.Start();
                stream = System.IO.File.Open(@"c:\temp.txt", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
                if (stream == null)
                {
                    return(false);
                }
                stream.Seek(_Instance._InitFileSize, System.IO.SeekOrigin.Begin);
                _Instance.GetErrorSession(stream, out errorCountDurungSession, out lineLog);
                EconfTools.QueryPerfCounter.Instance.Stop();
                result = EconfTools.QueryPerfCounter.Instance.Duration();
                Tools.Trace.WriteLog("EndSessionLog GetErrorSession :" + result + " nanos");
                success = true;
            }
            catch (Exception exception)
            {
                Tools.Trace.WriteLine(exception);
            }
            return(success);
        }