internal static void RemoveListenersByName(Collection <PSTraceSource> matchingSources, string[] listenerNames, bool fileListenersOnly)
        {
            Collection <WildcardPattern> patterns = SessionStateUtilities.CreateWildcardsFromStrings(listenerNames, WildcardOptions.IgnoreCase);

            foreach (PSTraceSource source in matchingSources)
            {
                for (int i = source.Listeners.Count - 1; i >= 0; i--)
                {
                    TraceListener listener = source.Listeners[i];
                    if ((!fileListenersOnly || (listener is TextWriterTraceListener)) && SessionStateUtilities.MatchesAnyWildcardPattern(listener.Name, patterns, true))
                    {
                        listener.Flush();
                        listener.Close();
                        source.Listeners.RemoveAt(i);
                    }
                }
            }
        }
        /// <summary>
        /// Removes the tracelisteners from the specified trace sources.
        /// </summary>
        internal static void RemoveListenersByName(
            Collection <PSTraceSource> matchingSources,
            string[] listenerNames,
            bool fileListenersOnly)
        {
            Collection <WildcardPattern> listenerMatcher =
                SessionStateUtilities.CreateWildcardsFromStrings(
                    listenerNames,
                    WildcardOptions.IgnoreCase);

            // Loop through all the matching sources and remove the matching listeners

            foreach (PSTraceSource source in matchingSources)
            {
                // Get the indexes of the listeners that need to be removed.
                // This is done because we cannot remove the listeners while
                // we are enumerating them.

                for (int index = source.Listeners.Count - 1; index >= 0; --index)
                {
                    TraceListener listenerToRemove = source.Listeners[index];

                    if (fileListenersOnly && !(listenerToRemove is TextWriterTraceListener))
                    {
                        // Since we only want to remove file listeners, skip any that
                        // aren't file listeners
                        continue;
                    }

                    // Now match the names

                    if (SessionStateUtilities.MatchesAnyWildcardPattern(
                            listenerToRemove.Name,
                            listenerMatcher,
                            true))
                    {
                        listenerToRemove.Flush();
                        listenerToRemove.Dispose();
                        source.Listeners.RemoveAt(index);
                    }
                }
            }
        }
示例#3
0
 public static void SetOutputStream(string filename)
 {
     if (filename != null)
     {
         TextWriter tw = TextWriter.Synchronized(new StreamWriter(filename, false));
         SysTrace.Listeners.Add(
             new TextWriterTraceListener(tw, "nc"));
         SysTrace.AutoFlush = true;
     }
     else
     {
         TraceListener listener = SysTrace.Listeners["nc"];
         if (listener != null)
         {
             SysTrace.Listeners.Remove(listener);
             listener.Flush();
             listener.Close();
         }
     }
 }
示例#4
0
        public async Task Dispose()
        {
            if (disposed)
            {
                return;
            }
            disposed = true;
            var tcs = new TaskCompletionSource <int>();

            await this.ModelObjects.SynchronizationContext.Invoke(() =>
            {
                var mainFormView = Mocks.Views.CreateMainFormView();
                mainFormView.When(x => x.ForceClose()).Do(x => tcs.SetResult(0));
                ViewModel.MainForm.OnClosing();
            });

            await tcs.Task;

            traceListener.Flush();
        }
 public void Log(string message, LevelEnum level, DateTime time)
 {
     _traceListener.WriteLine(message + " (" + time + ")", level.ToString());
     _traceListener.Flush();
 }
示例#6
0
 public void Flush()
 {
     _listener.Flush();
 }
 public override void Flush() => Lock(() => listener.Flush());