Esempio 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;
        }
Esempio n. 2
0
    /// <summary>
    /// Start the logging service
    /// </summary>
    public override void AddListener(string LogFile)
    {
        Trace.Listeners.Clear();

        try
        {
            twtl = new TextWriterTraceListener(LogFile);

            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();
            }
        }
    }
Esempio n. 3
0
    /// <summary>
    /// Stops and disposes of the logging service
    /// </summary>
    public override void RemoveListener()
    {
        Trace.Listeners.Remove(twtl);
        Trace.Listeners.Remove(ctl);
        Trace.Close();

        if (ctl != null)
        {
            ctl.Close();

            ctl.Dispose();
        }

        if (twtl != null)
        {
            twtl.Close();

            twtl.Dispose();
        }
    }
 public static void Teardown()
 {
     Debug.Unindent();
     Debug.Listeners.Remove(traceListener);
     traceListener.Dispose();
 }