• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# TraceSource类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ActivityIdChangedIfNewGuidSpecified

            public void ActivityIdChangedIfNewGuidSpecified()
            {
                var traceSource = new TraceSource(MethodBase.GetCurrentMethod().Name, SourceLevels.All);
                var activityId = Guid.NewGuid();

                using (new ActivityScope(traceSource, activityId))
                    Assert.Equal(activityId, Trace.CorrelationManager.ActivityId);
            }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:8,代码来源:ActivityScopeTests.cs


示例17: ConnectionBase

        protected ConnectionBase(TraceSource traceSource)
        {
            this.id = Interlocked.Increment(ref connectionIdCount);

              Interlocked.CompareExchange(ref connectionIdCount, 0, int.MaxValue);

              this.traceSource = traceSource;
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:8,代码来源:ConnectionBase.cs


示例18: Dump

 internal static void Dump(TraceSource traceSource, object obj, string method, byte[] buffer, int offset, int length)
 {
     if (ValidateSettings(traceSource, TraceEventType.Verbose))
     {
         if (buffer == null)
         {
             PrintLine(traceSource, TraceEventType.Verbose, 0, "(null)");
         }
         else if (offset > buffer.Length)
         {
             PrintLine(traceSource, TraceEventType.Verbose, 0, "(offset out of range)");
         }
         else
         {
             PrintLine(traceSource, TraceEventType.Verbose, 0, "Data from " + GetObjectName(obj) + "#" + ValidationHelper.HashString(obj) + "::" + method);
             int maxDumpSizeSetting = GetMaxDumpSizeSetting(traceSource);
             if (length > maxDumpSizeSetting)
             {
                 PrintLine(traceSource, TraceEventType.Verbose, 0, "(printing " + maxDumpSizeSetting.ToString(NumberFormatInfo.InvariantInfo) + " out of " + length.ToString(NumberFormatInfo.InvariantInfo) + ")");
                 length = maxDumpSizeSetting;
             }
             if ((length < 0) || (length > (buffer.Length - offset)))
             {
                 length = buffer.Length - offset;
             }
             if (GetUseProtocolTextSetting(traceSource))
             {
                 string msg = "<<" + WebHeaderCollection.HeaderEncoding.GetString(buffer, offset, length) + ">>";
                 PrintLine(traceSource, TraceEventType.Verbose, 0, msg);
             }
             else
             {
                 do
                 {
                     int num2 = Math.Min(length, 0x10);
                     string str2 = string.Format(CultureInfo.CurrentCulture, "{0:X8} : ", new object[] { offset });
                     for (int i = 0; i < num2; i++)
                     {
                         str2 = str2 + string.Format(CultureInfo.CurrentCulture, "{0:X2}", new object[] { buffer[offset + i] }) + ((i == 7) ? '-' : ' ');
                     }
                     for (int j = num2; j < 0x10; j++)
                     {
                         str2 = str2 + "   ";
                     }
                     str2 = str2 + ": ";
                     for (int k = 0; k < num2; k++)
                     {
                         str2 = str2 + (((buffer[offset + k] < 0x20) || (buffer[offset + k] > 0x7e)) ? '.' : ((char) buffer[offset + k]));
                     }
                     PrintLine(traceSource, TraceEventType.Verbose, 0, str2);
                     offset += num2;
                     length -= num2;
                 }
                 while (length > 0);
             }
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:58,代码来源:Logging.cs


示例19: SocketClient

 /// <summary>
 /// 
 /// </summary>
 static SocketClient()
 {
     #if !NETFX_CORE
     TraceSource = new TraceSource("HigLabo.Net.SocketClient");
     #endif
     #if !NETFX_CORE && !DEBUG
     TraceSource.Listeners.Clear();
     #endif
 }
开发者ID:fengweijp,项目名称:higlabo,代码行数:12,代码来源:SocketClient.cs


示例20: DoNotTraceStartEventWhenTracingDisabled

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

                traceSource.Listeners.Add(listener);
                using (new LogicalOperationScope(traceSource, traceSource.Name, traceEnabled: false))
                    Assert.Equal(0, listener.Messages.Count(m => m.Trim() == $"Logical operation {traceSource.Name} started"));
            }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:9,代码来源:LogicalOperationScopeTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Tracer类代码示例发布时间:2022-05-24
下一篇:
C# TraceRecord类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap