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


C# TraceSource类代码示例

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


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

示例1: NewLogicalOperationPushedOnToStack

            public void NewLogicalOperationPushedOnToStack()
            {
                var traceSource = new TraceSource(MethodBase.GetCurrentMethod().Name, SourceLevels.All);

                using (new LogicalOperationScope(traceSource, traceSource.Name))
                    Assert.Equal("NewLogicalOperationPushedOnToStack", Trace.CorrelationManager.LogicalOperationStack.Peek());
            }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:7,代码来源:LogicalOperationScopeTests.cs

示例2: SetSourceSwitchTest

 public void SetSourceSwitchTest()
 {
     var trace = new TraceSource("TestTraceSource");
     var @switch = new SourceSwitch("TestTraceSwitch");
     trace.Switch = @switch;
     Assert.Equal(@switch, trace.Switch);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:TraceSourceClassTests.cs

示例3: Associate

 internal static void Associate(TraceSource traceSource, object objA, object objB)
 {
     if (ValidateSettings(traceSource, TraceEventType.Information))
     {
         PrintLine(traceSource, TraceEventType.Information, 0, "Associating " + (GetObjectName(objA) + "#" + ValidationHelper.HashString(objA)) + " with " + (GetObjectName(objB) + "#" + ValidationHelper.HashString(objB)));
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:Logging.cs

示例4: Enter

 internal static void Enter(TraceSource source, string method)
 {
     if(source.Switch.ShouldTrace(TraceEventType.Verbose))
     {
         source.TraceEvent(TraceEventType.Verbose, 0, "Entering --> " + method);
     }
 }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:7,代码来源:Logging.cs

示例5: Leave

 internal static void Leave(TraceSource source, string message)
 {
     if (source.Switch.ShouldTrace(TraceEventType.Verbose))
     {
         source.TraceEvent(TraceEventType.Verbose, 0, "Leaving <-- " + message);
     }
 }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:7,代码来源:Logging.cs

示例6: TestTcpTraceListener

        public async Task TestTcpTraceListener()
        {
            var listener = new TcpListener(IPAddress.Loopback, 0);
            listener.Start();
            int port = ((IPEndPoint)listener.Server.LocalEndPoint).Port;


            var traceSource = new TraceSource("UnitTestLogger");
            traceSource.Listeners.Remove("Default");
            traceSource.Switch.Level = SourceLevels.All;
            traceSource.Listeners.Add(new TcpTraceListener(
                                            IPAddress.Loopback, port, 
                                            new ExponentialBackoffTcpReconnectionPolicy()));

            var listenerClient = await listener.AcceptTcpClientAsync();

            traceSource.TraceEvent(TraceEventType.Information, 100, "Boris");

            var receiverReader = new StreamReader(listenerClient.GetStream());
            var line = await receiverReader.ReadLineAsync();

            Assert.True(line.EndsWith("UnitTestLogger Information: 100 : Boris"));

            listenerClient.Close();
            listener.Stop();
            traceSource.Close();
        }
开发者ID:JimSimpkins13,项目名称:splunk-library-dotnetlogging,代码行数:27,代码来源:TestTcp.cs

示例7: Run

		public override void Run()
		{
			try
			{
				var m = Helper.FormatTrace("Staring the Scheduler", "SchedulerWorkerRole", "Run");
				var traceSource = new TraceSource("VirtoCommerce.ScheduleService.Trace");
				traceSource.TraceEvent(TraceEventType.Information, 0, m);

				string cloudContext;
				if (RoleEnvironment.IsAvailable)
				{
					cloudContext = String.Format("{0}|{1}",
						RoleEnvironment.DeploymentId,
						RoleEnvironment.CurrentRoleInstance.Id);
				}
				else
				{
					cloudContext = Guid.NewGuid().ToString();
				}

				var jobScheduler = new JobScheduler(cloudContext, traceSource, () => AzureConfiguration.Instance.AzureStorageAccount, new Settings());

                traceSource.TraceEvent(TraceEventType.Information, 0, Helper.FormatTrace("Staring the Scheduler", "SchedulerWorkerRole", "Run", "Starting Paralel.Invoke", cloudContext));

				Parallel.Invoke(
					jobScheduler.JobsManagerProcess,
					jobScheduler.SchedulerProcess);
			}
			catch (Exception ex)
			{
				var m = Helper.FormatException(ex, "WorkerRole", "Run");
				var traceSource = new TraceSource("VirtoCommerce.ScheduleService.Trace");
				traceSource.TraceEvent(TraceEventType.Error, 0, m);
			}
		}
开发者ID:gitter-badger,项目名称:vc-community-1.x,代码行数:35,代码来源:SchedulerWorkerRole.cs

示例8: EmailFloodManyThreadsMax100

        public void EmailFloodManyThreadsMax100()
        {
            TraceSource source = new TraceSource("emailFlood2Source");

            Action d = () =>
            {
                try
                {
                    var guid = Guid.NewGuid();
                    source.TraceEvent(TraceEventType.Warning, 0, "Message 1 - {0}", guid);
                    source.TraceEvent(TraceEventType.Error, 0, "Message 2 - {0}", guid);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Action exception: {0}", ex));
                }
            };

            for (int i = 0; i < 200; i++)
            {
                d.BeginInvoke(null, null);
            }

            // Need to wait, otherwise messages haven't been sent and Assert throws exception
            System.Threading.Thread.Sleep(3000);

            AssertMessagesSent(100, "Should be limited by max traces of 100.");
        }
开发者ID:amccool,项目名称:essentialdiagnostics,代码行数:28,代码来源:EmailTests.cs

示例9: CanDisposeRepeatedly

            public void CanDisposeRepeatedly()
            {
                var traceSource = new TraceSource(MethodBase.GetCurrentMethod().Name, SourceLevels.All);

                using (var context = new LogicalOperationScope(traceSource, traceSource.Name))
                    context.Dispose();
            }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:7,代码来源:LogicalOperationScopeTests.cs

示例10: Main

        static void Main(string[] args)
        {
            EnableSelfSignedCertificates();

            Uri uri = new Uri("https://localhost:8088");
            string token = "BEC47D17-AC4A-49ED-834B-969745D24550";

            var trace = new TraceSource("conf-demo");
            trace.Switch.Level = SourceLevels.All;
            var listener = new HttpEventCollectorTraceListener(uri, token);
            trace.Listeners.Add(listener);

            HashSet<string> files = new HashSet<string>();

            while (true)
            {
                string[] currentFiles = Directory.GetFiles(args[0]);
                foreach (string s in currentFiles)
                {
                    if (!files.Contains(s))
                    {
                        files.Add(s);
                        string ascii = ToAscii(s.Substring(s.LastIndexOf('\\') + 1), new Bitmap(s, true));

                        trace.TraceInformation(ascii);
                        trace.Flush();
                    }
                }
                Thread.Sleep(200);
            }
        }
开发者ID:JianLeeGit,项目名称:playground,代码行数:31,代码来源:Program.cs

示例11: ReturnName

            public void ReturnName()
            {
                var traceSource = new TraceSource(MethodBase.GetCurrentMethod().Name, SourceLevels.All);

                using (var context = new LogicalOperationScope(traceSource, traceSource.Name))
                    Assert.Equal(traceSource.Name, context.ToString());
            }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:7,代码来源:LogicalOperationScopeTests.cs

示例12: Invoke

        public Task Invoke(IDictionary<string, object> env)
        {
            // The TraceSource is assumed to be the same across all requests.

            traceSource = traceSource ?? new Request(env).Get<TraceSource>("host.TraceSource");

            if (traceSource == null)
            {
                return nextApp(env);
            }

            try
            {
                TraceCall(env);
                return nextApp(env).Then(() =>
                {
                    TraceResult(env);
                })
                .Catch(errorInfo =>
                {
                    TraceException(errorInfo.Exception, "asynchronously");
                    return errorInfo.Throw();
                });
            }
            catch (Exception ex)
            {
                TraceException(ex, "synchronously");
                throw;
            }
        }
开发者ID:owin,项目名称:museum-piece-gate,代码行数:30,代码来源:RequestTracer.cs

示例13: ShouldLogNetworkCommunication

        public void ShouldLogNetworkCommunication()
        {
            // Setup source and listener
            string initializationString =
                @"name = XmlLogger; logrootpath = c:\logs\; staticpattern = lognc_; maxSizeBytes = 200000;";

            XmlWriterRollingTraceListener traceListener =
                new XmlWriterRollingTraceListener(initializationString);

            TraceSource log = new TraceSource("Test", SourceLevels.All);

            log.Listeners.Clear();
            log.Listeners.Add(traceListener);

            // Start Activity #1
            Guid activity1Guid = Guid.NewGuid();

            Trace.CorrelationManager.ActivityId = activity1Guid;

            log.TraceEvent(TraceEventType.Start, 2, "Activity #1");

            // log information inside Activity #1
            log.TraceInformation("Going to execute HttpWebRequest from Activity #1");

            HttpWebRequest request = HttpWebRequest.Create("http://www.google.com/") as HttpWebRequest;
            WebResponse response = request.GetResponse();

            using (StreamReader s = new StreamReader(response.GetResponseStream()))
            {
                string value = s.ReadToEnd();
            }

            // Complete Activity #1
            log.TraceEvent(TraceEventType.Stop, 8, "Completing Activity #1");
        }
开发者ID:alienwaredream,项目名称:toolsdotnet,代码行数:35,代码来源:LoggingTest.cs

示例14: TraceListenerEx

			public TraceListenerEx(TraceSource source)
			{
				if (source == null)
					throw new ArgumentNullException("source");

				_source = source;
			}
开发者ID:yadrewn,项目名称:StockSharpShared_Before2016_05_25,代码行数:7,代码来源:TraceSource.cs

示例15: TraceInternal

        private static void TraceInternal(TraceSource traceSource, int eventId, TraceLevel traceLevel, string message)
        {
            if (traceSource == null) 
                return;

            var traceEventType = ConvertTraceLevelToTraceEventType(traceLevel);
            traceSource.TraceEvent(traceEventType, eventId, message);
        }
开发者ID:p69,项目名称:magellan-framework,代码行数:8,代码来源:TraceExtensions.cs


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