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


C# TraceSource.Close方法代码示例

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


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

示例1: Main

        public static void Main(string[] args)
        {
            TraceSource traceSource = new TraceSource("myTraceSource", SourceLevels.All);

            traceSource.TraceInformation("Tracing application...");
            traceSource.TraceEvent(TraceEventType.Critical, 0, "Critical trace");
            traceSource.TraceData(TraceEventType.Information, 1, new object[] { "a", "b", "c" });

            traceSource.Flush();
            traceSource.Close();
        }
开发者ID:nissbran,项目名称:Training-Certifications,代码行数:11,代码来源:Program.cs

示例2: HowToUseTheTraceSourceClass

        public static void HowToUseTheTraceSourceClass()
        {
            TraceSource traceSource = new TraceSource("myTraceSource", SourceLevels.All);

            traceSource.TraceInformation("Tracing app");
            traceSource.TraceEvent(TraceEventType.Critical, 0, "Critical trace");
            traceSource.TraceData(TraceEventType.Information, 1, new object[] { "a", "b", "c" });

            traceSource.Flush();
            traceSource.Close();
        }
开发者ID:Chaek,项目名称:MCSD,代码行数:11,代码来源:TraceSourceExample.cs

示例3: Main

        static void Main(string[] args)
        {
            TraceSource myTraceSource = new TraceSource("MyConsoleApp");

            myTraceSource.TraceEvent(TraceEventType.Error, 1, "Tracing Error Message.");
            myTraceSource.TraceEvent(TraceEventType.Warning, 2, "Tracing Warning Message.");
            myTraceSource.TraceEvent(TraceEventType.Information, 3, "Tracing Information.");
            myTraceSource.TraceEvent(TraceEventType.Verbose, 4, "Tracing Verbose Message.");
            myTraceSource.TraceEvent(TraceEventType.Critical, 5, "Tracing Critical Message.");

            myTraceSource.Close();
        }
开发者ID:pcibraro,项目名称:RealtimeTracing,代码行数:12,代码来源:Program.cs

示例4: DoTrace

 public static void DoTrace()
 {
     Stream outputFile = File.Create("tracefile.txt");
     TextWriterTraceListener textListener =
     new TextWriterTraceListener(outputFile);
     TraceSource traceSource = new TraceSource("myTraceSource",
     SourceLevels.All);
     traceSource.Listeners.Clear();
     traceSource.Listeners.Add(textListener);
     traceSource.TraceInformation("Trace output");
     traceSource.Flush();
     traceSource.Close();
 }
开发者ID:ErhanGDC,项目名称:MyWorks,代码行数:13,代码来源:Program.cs

示例5: Main

        static void Main(string[] args)
        {
            TraceSource traceSource = new TraceSource("myTraceSource", SourceLevels.All);

            traceSource.TraceInformation("Tracing application.");
            traceSource.TraceEvent(TraceEventType.Critical, 0, "Critical trace");
            traceSource.TraceData(TraceEventType.Information, 1, new object[] { "a", "b", "c" });

            traceSource.Flush();
            traceSource.Close();

            Console.WriteLine("Press a key to exit");
            Console.ReadKey();
        }
开发者ID:jbijoux,项目名称:Exam70_483,代码行数:14,代码来源:Program.cs

示例6: HowToUseTheTraceListenerClass

        public static void HowToUseTheTraceListenerClass()
        {
            Stream outputFile = File.Create("traceFile.txt");
            TextWriterTraceListener textListener = new TextWriterTraceListener(outputFile);

            TraceSource traceSource = new TraceSource("myTraceSource", SourceLevels.All);

            traceSource.Listeners.Clear();
            traceSource.Listeners.Add(textListener);

            traceSource.TraceInformation("Tracing app");
            traceSource.TraceEvent(TraceEventType.Critical, 0, "Critical trace");
            traceSource.TraceData(TraceEventType.Information, 1, new object[] { "a", "b", "c" });

            traceSource.Flush();
            traceSource.Close();
        }
开发者ID:Chaek,项目名称:MCSD,代码行数:17,代码来源:TraceSourceListenerExample.cs

示例7: Main

        static void Main(string[] args)
        {
            Debug.WriteLine("Starting application");
            Debug.Indent();
            int i = 1 + 2;
            Debug.Assert(i == 3);
            Debug.WriteLineIf(i > 0, "i is greater than 0");

            TraceSource traceSource = new TraceSource("myTraceSource", SourceLevels.All);
            traceSource.TraceInformation("Tracing application..");
            traceSource.TraceEvent(TraceEventType.Critical, 0, "Critical trace");
            traceSource.TraceData(TraceEventType.Information, 1,
            new object[] { "a", "b", "c" });
            traceSource.Flush();
            traceSource.Close();

            DoTrace();

            Console.ReadLine();
        }
开发者ID:ErhanGDC,项目名称:MyWorks,代码行数:20,代码来源:Program.cs

示例8: Main

        static void Main(string[] args)
        {
            TraceSource myTraceSource = new TraceSource("MyConsoleApp");

            myTraceSource.TraceEvent(TraceEventType.Error, 1, "Tracing Error Message.");
            myTraceSource.TraceEvent(TraceEventType.Warning, 2, "Tracing Warning Message.");
            myTraceSource.TraceEvent(TraceEventType.Information, 3, "Tracing Information.");
            myTraceSource.TraceEvent(TraceEventType.Verbose, 4, "Tracing Verbose Message.");
            myTraceSource.TraceEvent(TraceEventType.Critical, 5, "Tracing Critical Message.");

            string msg = String.Empty;
            Console.Write("Napisz komunikat do wysłania!" + Environment.NewLine);
            bool _go = true;
            while (_go)
            {
                msg = Console.ReadLine();
                if (msg.Contains("exit"))
                {
                    _go = false;
                }
                myTraceSource.TraceEvent(TraceEventType.Information, 3, msg);
            }
            myTraceSource.Close();
        }
开发者ID:Zawulon,项目名称:jseverywhere,代码行数:24,代码来源:Program.cs

示例9: LogExceptionInternal

		private static void LogExceptionInternal(string message, TraceEventType severity)
		{
			var traceSource = new TraceSource(Assembly.GetEntryAssembly().GetName().Name);
			traceSource.TraceEvent(severity, 0, message);
			traceSource.Flush();
			traceSource.Close();
		}
开发者ID:Philo,项目名称:Revalee,代码行数:7,代码来源:Supervisor.cs

示例10: LogToEmailUsingDirectObjectOnlyResultsInOneMessage

        public void LogToEmailUsingDirectObjectOnlyResultsInOneMessage()
        {
            MockEmailTraceListener listener = new MockEmailTraceListener("[email protected];[email protected]", "[email protected]",
                                        "EntLib-Logging ->", "has occurred", "smtphost");

            TraceSource source = new TraceSource("unnamed", SourceLevels.All);
            source.Listeners.Add(listener);

            int numMessages = listener.MessagesSent;

            source.TraceData(TraceEventType.Error, 1, new TestCustomObject());
            source.Close();

            int newNumMessages = listener.MessagesSent;

            Assert.AreEqual(numMessages, newNumMessages - 1);
        }
开发者ID:bnantz,项目名称:NCS-V2-0,代码行数:17,代码来源:EmailTraceListenerFixture.cs

示例11: GetTraceSourceWithListeners_Locked

        // Gets the name of the closest "parent" TraceRoute that has listeners, or null otherwise.
        private static TraceSource GetTraceSourceWithListeners_Locked(string name, SourceLevels sourceLevels)
        {
            string[] parts = name.Split(new char[] { '.' }, StringSplitOptions.None);

            List<string> namesToTest = new List<string>();
            StringBuilder sb = new StringBuilder();
            foreach (var part in parts)
            {
                if (sb.Length > 0)
                    sb.Append(".");
                sb.Append(part);

                string partialName = sb.ToString();
                namesToTest.Add(partialName);
            }

            namesToTest.Reverse();
            foreach (var testName in namesToTest)
            {
                TraceSource ts = null;
                ts = new TraceSource(testName, sourceLevels);
                // no listeners? skip
                if (ts.Listeners == null || ts.Listeners.Count == 0)
                {
                    ts.Close();
                    continue;
                }
                // more than one listener? use this TraceSource
                if (ts.Listeners.Count > 1)
                    return ts;
                TraceListener listener = ts.Listeners[0];
                // single listener isn't DefaultTraceListener? use this TraceRoute
                if (!(listener is DefaultTraceListener))
                    return ts;
                // single listener is DefaultTraceListener but isn't named Default? use this TraceRoute
                if (!string.Equals(listener.Name, "Default", StringComparison.Ordinal))
                    return ts;

                // not the TraceSource we're looking for, close it
                ts.Close();
            }

            // nothing found? no listeners are configured for any of the names, even the original,
            // so return null to signify failure
            return null;
        }
开发者ID:rguarino4,项目名称:aws-sdk-net,代码行数:47,代码来源:Logger.cs

示例12: LogToDatabaseUsingDirectObjectOnlyResultsInOneMessage

        public void LogToDatabaseUsingDirectObjectOnlyResultsInOneMessage()
        {
            FormattedDatabaseTraceListener listener = new FormattedDatabaseTraceListener(new SqlDatabase(connectionString), "WriteLog", "AddCategory", new TextFormatter("TEST{newline}TEST"));

            TraceSource source = new TraceSource("notfromconfig", SourceLevels.All);
            source.Listeners.Add(listener);
            int numMessages = GetNumberOfLogMessage("LoggingDb");

            source.TraceData(TraceEventType.Error, 1, new TestCustomObject());
            source.Close();

            int newNumMessages = GetNumberOfLogMessage("LoggingDb");

            Assert.AreEqual(numMessages, newNumMessages - 1);
        }
开发者ID:bnantz,项目名称:NCS-V2-0,代码行数:15,代码来源:FormattedDatabaseTraceListenerFixture.cs

示例13: AttachToAllTraceSources

        //based on: http://stackoverflow.com/questions/3303126/how-to-get-the-value-of-private-field-in-c
        //        and http://stackoverflow.com/questions/23664573/tracesource-and-tracelistener-quietly-fail-to-do-anything
        // safe to call multiple times
        private static void AttachToAllTraceSources(TraceListener yourListener)
        {
            List<string> sourceList = new List<string>();

            TraceSource ts = new TraceSource("foo");
            List<WeakReference> list = (List<WeakReference>)GetInstanceField(typeof(TraceSource), ts, "tracesources");
            for(int count = 0; count < list.Count; count++)
            {
                WeakReference weakReference = list[count];
                if(weakReference.IsAlive)
                {
                    TraceSource source = (weakReference.Target as TraceSource);
                    if(source != null && source.Name != "foo")
                    {
                        if(!source.Listeners.Contains(yourListener))	//This works after overriding Equals()
                        {
                            source.Listeners.Add(yourListener);
                            sourceList.Add(source.Name);
                        }
                    }
                }
            }
            ts.Close();

            _traceSource.TraceEvent(TraceEventType.Information, 57, "Jkh.TraceListenerRtf is listening to : {0}", string.Join(",",sourceList));
        }
开发者ID:jeoffman,项目名称:JkhSettings,代码行数:29,代码来源:TraceListenerRtf.cs

示例14: LogToMsmqUsingDirectObjectOnlyResultsInOneMessage

        public void LogToMsmqUsingDirectObjectOnlyResultsInOneMessage()
        {
            ILogFormatter formatter = new BinaryLogFormatter();
            MsmqTraceListener listener =
                new MsmqTraceListener("unnamed", CommonUtil.MessageQueuePath, formatter, MessagePriority.Low, true,
                                      MsmqTraceListenerData.DefaultTimeToBeReceived, MsmqTraceListenerData.DefaultTimeToReachQueue,
                                      false, false, false, MsmqTraceListenerData.DefaultTransactionType, new MockMsmqInterfaceFactory());
            TraceSource source = new TraceSource("unnamed", SourceLevels.All);
            source.Listeners.Add(listener);

            int numMessages = MockMsmqInterface.Instance.MessageCount;

            source.TraceData(TraceEventType.Error, 1, new TestCustomObject());
            source.Close();

            int newNumMessages = MockMsmqInterface.Instance.MessageCount;

            Assert.AreEqual(numMessages, newNumMessages - 1);
        }
开发者ID:bnantz,项目名称:NCS-V2-0,代码行数:19,代码来源:MsmqTraceListenerFixture.cs

示例15: LogError

 private static void LogError(string tracesource, int id, string message)
 {
     TraceSource TraceSource = new TraceSource(tracesource);
     TraceSource.TraceData(TraceEventType.Error, id, message);
     TraceSource.Close();
 }
开发者ID:broersa,项目名称:BekijkHet.Utilities,代码行数:6,代码来源:Static.cs


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