当前位置: 首页>>代码示例>>C#>>正文


C# Diagnostics.TraceListener类代码示例

本文整理汇总了C#中System.Diagnostics.TraceListener的典型用法代码示例。如果您正苦于以下问题:C# TraceListener类的具体用法?C# TraceListener怎么用?C# TraceListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TraceListener类属于System.Diagnostics命名空间,在下文中一共展示了TraceListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AsynchronousTraceListenerWrapper

        /// <summary>
        /// Initializes a new instance of the <see cref="AsynchronousTraceListenerWrapper" /> class.
        /// </summary>
        /// <param name="wrappedTraceListener">The wrapped trace listener.</param>
        /// <param name="ownsWrappedTraceListener">Indicates whether the wrapper should dispose the wrapped trace listener.</param>
        /// <param name="bufferSize">Size of the buffer for asynchronous requests.</param>
        /// <param name="maxDegreeOfParallelism">The max degree of parallelism for thread safe listeners. Specify <see langword="null"/> to use the current core count.</param>
        /// <param name="disposeTimeout">The timeout for waiting to complete buffered requests when disposing. When <see langword="null" /> the default of <see cref="Timeout.InfiniteTimeSpan" /> is used.</param>
        public AsynchronousTraceListenerWrapper(
            TraceListener wrappedTraceListener,
            bool ownsWrappedTraceListener = true,
            int? bufferSize = DefaultBufferSize,
            int? maxDegreeOfParallelism = null,
            TimeSpan? disposeTimeout = null)
        {
            Guard.ArgumentNotNull(wrappedTraceListener, "wrappedTraceListener");
            CheckBufferSize(bufferSize);
            CheckMaxDegreeOfParallelism(maxDegreeOfParallelism);
            CheckDisposeTimeout(disposeTimeout);

            this.wrappedTraceListener = wrappedTraceListener;
            this.ownsWrappedTraceListener = ownsWrappedTraceListener;
            this.disposeTimeout = disposeTimeout ?? Timeout.InfiniteTimeSpan;

            this.closeSource = new CancellationTokenSource();
            this.requests = bufferSize != null ? new BlockingCollection<Action<TraceListener>>(bufferSize.Value) : new BlockingCollection<Action<TraceListener>>();

            if (this.wrappedTraceListener.IsThreadSafe)
            {
                this.maxDegreeOfParallelism = maxDegreeOfParallelism.HasValue ? maxDegreeOfParallelism.Value : Environment.ProcessorCount;
                this.asyncProcessingTask = Task.Factory.StartNew(this.ProcessRequestsInParallel, CancellationToken.None, TaskCreationOptions.HideScheduler | TaskCreationOptions.LongRunning, TaskScheduler.Default);
            }
            else
            {
                this.asyncProcessingTask = Task.Factory.StartNew(this.ProcessRequests, CancellationToken.None, TaskCreationOptions.HideScheduler | TaskCreationOptions.LongRunning, TaskScheduler.Default);
            }
        }
开发者ID:Brar,项目名称:entlib,代码行数:37,代码来源:AsynchronousTraceListenerWrapper.cs

示例2: Add

        /// <devdoc>
        /// <para>Adds a <see cref='System.Diagnostics.TraceListener'/> to the list.</para>
        /// </devdoc>
        public int Add(TraceListener listener) {                
            InitializeListener(listener);

            lock (TraceInternal.critSec) {
                return list.Add(listener);
            }        
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:10,代码来源:TraceListeners.cs

示例3: AddTraceListener

        // Add a TraceListener to a type
        public static void AddTraceListener(string type, TraceListener traceListener)
        {
            if (type == ListenerType.All)
            {
                lock (Tracers)
                {
                    foreach (var tracerKey in Tracers.Keys)
                        InternalAddListener(tracerKey, traceListener);
                }

                lock (TraceAll)
                {
                    TraceAll.Add(traceListener);
                }
            }
            else
            {
                lock (Tracers)
                {
                    if (!Tracers.ContainsKey(type))
                        throw new ArgumentException(string.Format("The trace type '{0}' must be registred before adding a trace listener.", type));

                    InternalAddListener(type, traceListener);
                }
            }
        }
开发者ID:FModolo,项目名称:AdvancedTrace,代码行数:27,代码来源:AdvancedTrace.cs

示例4: DatabaseTraceListener

 /// <summary>
 /// Initalizes a new instance of <see cref="DatabaseTraceListener"/>.
 /// </summary>
 public DatabaseTraceListener()
 {
     fallbackTraceListener = new XmlWriterRollingTraceListener(2000000, "dblogfallback");
     machineName = Environment.MachineName;
     modulePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
     appDomainName = AppDomain.CurrentDomain.FriendlyName;
 }
开发者ID:alienwaredream,项目名称:toolsdotnet,代码行数:10,代码来源:DatabaseTraceListener.cs

示例5: TraceSourceProvider

 /// <summary>
 /// Create a new instance of this trace manager
 /// </summary>
 public TraceSourceProvider(TraceListener listener)
 {
     // Create default source
        // source = new System.Diagnostics.TraceSource("TraceSourceApp", SourceLevels.All);
     if (listener != null)
         Source.Listeners.Add(listener);
 }
开发者ID:ukjiemeitao,项目名称:MyLibrary,代码行数:10,代码来源:TraceSourceProvider.cs

示例6: TraceOutputWindowPane

        /// <summary>
        /// Initializes a new instance of the <see cref="TraceOutputWindowPane"/> class.
        /// </summary>
        /// <param name="serviceProvider">The service provider.</param>
        /// <param name="shellEvents">The shell events.</param>
        /// <param name="outputPaneId">The output pane GUID, which must be unique and remain constant for a given pane.</param>
        /// <param name="outputPaneTitle">The output pane title.</param>
        /// <param name="traceSourceNames">The names of the trace sources to write to the output window pane.</param>
        public TraceOutputWindowPane(IServiceProvider serviceProvider, IShellEvents shellEvents, Guid outputPaneId, string outputPaneTitle, params string[] traceSourceNames)
        {
            Guard.NotNull(() => serviceProvider, serviceProvider);
            Guard.NotNull(() => shellEvents, shellEvents);
            Guard.NotNullOrEmpty(() => outputPaneTitle, outputPaneTitle);
            Guard.NotNull(() => traceSourceNames, traceSourceNames);

            this.serviceProvider = serviceProvider;
            this.outputPaneGuid = outputPaneId;
            this.outputPaneTitle = outputPaneTitle;
            this.traceSourceNames = traceSourceNames;
            this.shellEvents = shellEvents;

            this.shellEvents.ShellInitialized += this.OnShellInitialized;

            // Create a temporary writer that buffers events that happen 
            // before shell initialization is completed, so that we don't 
            // miss anything.
            this.temporaryWriter = new StringWriter(CultureInfo.CurrentCulture);
            this.listener = new TextWriterTraceListener(this.temporaryWriter, this.outputPaneTitle);
            this.listener.IndentLevel = 4;
            this.listener.Filter = defaultFilter;

            this.AddListenerToSources();
        }
开发者ID:NuPattern,项目名称:NuPattern,代码行数:33,代码来源:TraceOutputWindowPane.cs

示例7: WriteAll

        public static void WriteAll(ActionResult output, TraceListener listener)
        {
            Trace.Listeners.Clear();
            Trace.Listeners.Add(new ExtendedConsoleTraceListener());

            foreach (var lineOutput in output.Output)
            {
                switch (lineOutput.TraceEventType)
                {
                    case TraceEventType.Error:
                        Trace.TraceError(lineOutput.Message);
                        break;
                    case TraceEventType.Warning:
                        Trace.TraceWarning(lineOutput.Message);
                        break;
                    default:
                        Trace.WriteLine(lineOutput.Message);
                        break;
                }
            }

            if (output.Value != null)
            {
                Trace.TraceInformation(string.Format("=> {0}", output.Value.ToString()));
            }
        }
开发者ID:netxph,项目名称:redspect,代码行数:26,代码来源:TraceWriter.cs

示例8: AddListenerToSources

 private static void AddListenerToSources(Collection<PSTraceSource> matchingSources, TraceListener listener)
 {
     foreach (PSTraceSource source in matchingSources)
     {
         source.Listeners.Add(listener);
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:TraceListenerCommandBase.cs

示例9: Main

 private static void Main(string[] args)
 {
     var opts = new BenchmarkArgs();
     if (CommandLine.Parser.ParseArgumentsWithUsage(args, opts))
     {
         
         if (!string.IsNullOrEmpty(opts.LogFilePath))
         {
             BenchmarkLogging.EnableFileLogging(opts.LogFilePath);
             var logStream = new FileStream(opts.LogFilePath + ".bslog", FileMode.Create);
             BrightstarListener = new TextWriterTraceListener(logStream);
             BrightstarDB.Logging.BrightstarTraceSource.Listeners.Add(BrightstarListener);
             BrightstarDB.Logging.BrightstarTraceSource.Switch.Level = SourceLevels.All;
         }
     }
     else
     {
         var usage = CommandLine.Parser.ArgumentsUsage(typeof (BenchmarkArgs));
         Console.WriteLine(usage);
     }
     var runner = new BenchmarkRunner(opts);
     runner.Run();
     BenchmarkLogging.Close();
     BrightstarDB.Logging.BrightstarTraceSource.Close();
 }
开发者ID:jaensen,项目名称:BrightstarDB,代码行数:25,代码来源:Program.cs

示例10: AddTraceListener

		public void AddTraceListener(TraceListener traceListener)
		{
			lock (this.syncRoot)
			{
				this.tracer.Listeners.Add(traceListener);
			}
		}
开发者ID:kissstudio,项目名称:Topawes,代码行数:7,代码来源:ThreadSafeTracer.cs

示例11: TraceListenerFilterOnMultipleCollectionsWithCommonElementsDoesNotRepeatElements

        public void TraceListenerFilterOnMultipleCollectionsWithCommonElementsDoesNotRepeatElements()
        {
            TraceListenerFilter filter = new TraceListenerFilter();

            TraceListener listener1 = new MockTraceListener();
            TraceListener listener2 = new MockTraceListener();
            IList traceListenersCollection1 = new TraceListener[] { listener1, listener2 };
            TraceListener listener3 = new MockTraceListener();
            TraceListener listener4 = new MockTraceListener();
            IList traceListenersCollection2 = new TraceListener[] { listener2, listener3, listener4 };

            int i = 0;
            Dictionary<TraceListener, int> listeners = new Dictionary<TraceListener, int>();
            foreach (TraceListener listener in filter.GetAvailableTraceListeners(traceListenersCollection1))
            {
                i++;
                listeners[listener] = (listeners.ContainsKey(listener) ? listeners[listener] : 0) + 1;
            }
            foreach (TraceListener listener in filter.GetAvailableTraceListeners(traceListenersCollection2))
            {
                i++;
                listeners[listener] = (listeners.ContainsKey(listener) ? listeners[listener] : 0) + 1;
            }

            Assert.AreEqual(4, i);
            Assert.AreEqual(1, listeners[listener1]);
            Assert.AreEqual(1, listeners[listener2]);
            Assert.AreEqual(1, listeners[listener3]);
            Assert.AreEqual(1, listeners[listener4]);
        }
开发者ID:bnantz,项目名称:NCS-V2-0,代码行数:30,代码来源:TraceListenerFilterFixture.cs

示例12: OnConnection

		/// <summary>
		/// Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.
		/// </summary>
		/// <param name='application'>
		/// Root object of the host application.
		/// </param>
		/// <param name='connectMode'>
		/// Describes how the Add-in is being loaded.
		/// </param>
		/// <param name='addIn'>
		/// Object representing this Add-in.
		/// </param>
		/// /// <param name='custom'>
		/// Array of parameters that are host application specific.
		/// </param>
		/// <seealso class='IDTExtensibility2' />
		public void OnConnection(object application, ext_ConnectMode connectMode, object addIn, ref Array custom)
		{
			_application = (DTE2)application;
			_addIn = (AddIn)addIn;
			try
			{
				if (connectMode == ext_ConnectMode.ext_cm_Startup || connectMode == ext_ConnectMode.ext_cm_AfterStartup)
				{
					_listener = CreateTraceListener();
					_env = new ControllerEnvironment(new WindowHandle(_application.MainWindow.HWnd), _listener);
					_controller = CreateController();
					_controller.OnConnectionStateChange += OnConnectionStateChange;
					CreateCommands();
					CreateToolWindow();
					_listener.WriteLine("Addin initialized");
					if (connectMode == ext_ConnectMode.ext_cm_AfterStartup)
					{
						OnStartupComplete(ref custom);
					}
				}
			}
			catch (Exception ex)
			{
				if (_listener != null)
				{
					_listener.WriteLine(ex);
				}
			}
		}
开发者ID:TargetProcess,项目名称:Tp.Integration.Ide.VisualStudio,代码行数:45,代码来源:Connect.cs

示例13: AddListener

		/// <summary>
		/// Adds a listener to the source with the given <paramref name="sourceName"/>.
		/// </summary>
		public static void AddListener(string sourceName, TraceListener listener)
		{
			Guard.NotNullOrEmpty(() => sourceName, sourceName);
			Guard.NotNull(() => listener, listener);

			Tracer.Instance.AddListener(sourceName, listener);
		}
开发者ID:netfx,项目名称:extensions,代码行数:10,代码来源:TracerExtensibility.cs

示例14: ResilientMoveFile

		/// <summary>
		/// try, try, try... to move this file. tries for a predefined period, in case a very large file was copying, or times out
		/// note: blocks thread
		/// </summary>
		/// <param name="sourcePath">full path to source file</param>
		/// <param name="destinationPath">full path to destination file</param>
		/// <param name="logFile">log file to write to</param>
		/// <returns>true if file moved OK</returns>
		public static bool ResilientMoveFile (string sourcePath, string destinationPath, TraceListener logFile)
			{
			if (logFile != null)
				{
				logFile.WriteLine ("Moving file '" + sourcePath + "' to '" + destinationPath + "'");
				}

			// it may have been created, but might not be finished copying. need to wait until we can have accessto move it
			bool haveMoved = false;
			int tryCount = 0;
			DateTime timeStart = DateTime.Now;
			while (!haveMoved)
				{
				// try to get access for predefined period
				if (DateTime.Now - timeStart > TimeSpan.FromSeconds (EncoderFolderWatcherService.WatcherSettings.Default.retryFileCopyDurationSeconds))
					{
					throw new WatcherException ("  Failed to get access to '" + sourcePath + "' within established time period -- abandoning");
					}

				// try renaming file. if we dont have access we will get the IOException
				try
					{
					if (logFile != null)
						{
						logFile.WriteLine ("  Trying to get access to '" + sourcePath + "'");
						}

					File.Move (sourcePath, destinationPath);
					haveMoved = true;

					if (logFile != null)
						{
						logFile.WriteLine ("  Moved file '" + sourcePath + "' to '" + destinationPath + "'");
						}
					}
				catch (FileNotFoundException)
					{
					// source file moved underneath us (someone else claimed?)
					if (logFile != null)
						{
						logFile.WriteLine ("  file '" + sourcePath + "' moved from underneath us. This machine should not do the encode");
						}

					return false;
					}
				catch (IOException)
					{
					// did not have access. Wait a little                    
					if (logFile != null)
						{
						logFile.WriteLine ("  Could not get access to '" + sourcePath + "' ... sleeping 1 second before retrying (try " + (++tryCount) + ")");
						}

					Thread.Sleep (1000);
					}
				}

			return true;
			}
开发者ID:heinzsack,项目名称:DEV,代码行数:67,代码来源:Utilities.cs

示例15: AddListener

        public static void AddListener(TraceListener listener)
        {
            if (listener == null)
                throw new ArgumentNullException("listener");

            lock (listeners)
                listeners.Add(listener);
        }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:8,代码来源:Logger.cs


注:本文中的System.Diagnostics.TraceListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。