Ejemplo n.º 1
0
        /// <summary>
        /// Starts the trace listners.
        /// </summary>
        public static void StartTraceListners(string logFilePrefix = "RulePerf")
        {
            string logFilePath = "{1}-{0}.log".FormatWith(DateTime.Now.ToString("yyyy-MM-ddThh-mm-ssZ"), logFilePrefix);
            logFilePath = System.IO.Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location, logFilePath);
            TextWriterTraceListener textWriterTraceListener = new TextWriterTraceListener(logFilePath, "logListener");
            ConsoleTraceListener consoleTraceListener = new ConsoleTraceListener();

            ////Trace.Listeners.Clear();

            if (!Trace.Listeners.Contains(textWriterTraceListener.GetType(), textWriterTraceListener.Name))
            {
                Trace.Listeners.Add(textWriterTraceListener);
            }
            else
            {
                textWriterTraceListener.Dispose();
            }

            if (!Trace.Listeners.Contains(consoleTraceListener.GetType()))
            {
                Trace.Listeners.Add(consoleTraceListener);
            }
            else
            {
                consoleTraceListener.Dispose();
            }

            Trace.AutoFlush = true;
        }
Ejemplo n.º 2
0
 void Logging()
 {
     try
     {
         if (Log == false)
         {
             Log = true;
             Thread thread = new Thread(Boosting);
             thread.IsBackground = true;
             thread.Start();
             Directory.CreateDirectory(LogPath);
             if (!File.Exists(LogPath + @"\GClientService.Log"))
             {
                 var createLog = File.Create(LogPath + @"\GClientService.Log");
                 createLog.Dispose();
             }
             if (File.Exists(LogPath + @"\GClientService.Log"))
             {
                 File.Delete(LogPath + @"\GClientService-Previous.log");
             }
             bool TempExist = true;
             while (TempExist)
             {
                 if (File.Exists(LogPath + @"\GClientService-Previous.log"))
                 {
                     Thread.Sleep(50);
                 }
                 else
                 {
                     File.Move(LogPath + @"\GClientService.Log", LogPath + @"\GClientService-Previous.log");
                     TempExist = false;
                 }
             }
             Trace.Listeners.Clear();
             TextWriterTraceListener twtl = null;
             try
             {
                 twtl = new TextWriterTraceListener(LogPath + @"\GClientService.Log");
                 ConsoleTraceListener ctl = null;
                 try
                 {
                     ctl = new ConsoleTraceListener(false);
                     Trace.Listeners.Add(twtl);
                     Trace.Listeners.Add(ctl);
                     Trace.AutoFlush = true;
                 }
                 finally
                 {
                     if (ctl != null)
                     {
                         ctl.Dispose();
                     }
                 }
             }
             finally
             {
                 if (twtl != null)
                 {
                     twtl.Dispose();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Trace.WriteLine(DateTime.Now + Properties.Resources.ResourceManager.GetString("FailedOperationMessage") + "\n" + "          " + ex.Message);
     }
 }
Ejemplo n.º 3
0
        private bool disposedValue = false; // To detect redundant calls

        #endregion Fields

        #region Constructors

        //Main Environment Startup
        public MainWindow()
        {
            try
            {
                Hide();
                Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentCulture;
                InitializeComponent();
                //Logging
                try
                {
                    Variables.worker = new BackgroundWorker();
                    Directory.CreateDirectory(Variables.LogPath);
                    Directory.CreateDirectory(Variables.ImagePath);
                    if (!File.Exists(Variables.LogPath + @"\GClient.Log"))
                    {
                        var createLog = File.Create(Variables.LogPath + @"\GClient.Log");
                        createLog.Dispose();
                    }
                    if (File.Exists(Variables.LogPath + @"\GClient.Log"))
                    {
                        File.Delete(Variables.LogPath + @"\GClient-Previous.log");
                    }
                    bool TempExist = true;
                    while (TempExist)
                    {
                        if (File.Exists(Variables.LogPath + @"\GClient-Previous.log"))
                        {
                            Thread.Sleep(50);
                        }
                        else
                        {
                            File.Move(Variables.LogPath + @"\GClient.Log", Variables.LogPath + @"\GClient-Previous.log");
                            TempExist = false;
                        }
                    }
                    Trace.Listeners.Clear();
                    TextWriterTraceListener twtl = null;
                    try
                    {
                        twtl = new TextWriterTraceListener(Variables.LogPath + @"\GClient.Log");
                        ConsoleTraceListener ctl = null;
                        try
                        {
                            ctl = new ConsoleTraceListener(false);
                            Trace.Listeners.Add(twtl);
                            Trace.Listeners.Add(ctl);
                            Trace.AutoFlush = true;
                            Trace.WriteLine(DateTime.Now + " GClient GT is initializing: ");
                        }
                        finally
                        {
                            if (ctl != null)
                            {
                                ctl.Dispose();
                            }
                        }
                    }
                    finally
                    {
                        if (twtl != null)
                        {
                            twtl.Dispose();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(DateTime.Now + Properties.Resources.ResourceManager.GetString("FailedOperationMessage") + "\n" + "          " + ex.Message);
                    MessageBox.Show(Properties.Resources.ResourceManager.GetString("FailedOperationMessage") + "\n\n" + ex.Message, Properties.Resources.ResourceManager.GetString("FailedOperationTitle"), MessageBoxButton.OK, MessageBoxImage.Stop);
                }
                Variables.GUIShowing = false;
                label2.Content = "Version: " + System.Windows.Forms.Application.ProductVersion;
                SettingsFile();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(DateTime.Now + Properties.Resources.ResourceManager.GetString("FailedOperationMessage") + "\n" + "          " + ex.Message);
                MessageBox.Show(Properties.Resources.ResourceManager.GetString("FailedOperationMessage") + "\n\n" + ex.Message, Properties.Resources.ResourceManager.GetString("FailedOperationTitle"), MessageBoxButton.OK, MessageBoxImage.Stop);
            }
        }