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


C# TraceSource.TraceEvent方法代码示例

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


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

示例1: Run

        private 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);

                var 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,代码行数:25,代码来源:Program.cs

示例2: 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

示例3: Main

        private static void Main(string[] args)
        {
            using (CancellationTokenSource cts = new CancellationTokenSource())
            {
                TraceSource traceSource = new TraceSource("CleanupSample", SourceLevels.All);
                traceSource.Listeners.Add(new ConsoleTraceListener() { TraceOutputOptions = TraceOptions.DateTime | TraceOptions.ThreadId });

                CleanupGuard guard = new CleanupGuard();
                Task task = guard.RunAsync(g => RunSampleAsync(g, traceSource, cts.Token));

                Console.WriteLine("Press ENTER to stop.");
                Console.ReadLine();

                cts.Cancel();

                try
                {
                    task.Wait();
                }
                catch (Exception e)
                {
                    traceSource.TraceEvent(TraceEventType.Error, 0, "ERROR: {0}", e);
                }
            }
        }
开发者ID:knightfall,项目名称:writeasync,代码行数:25,代码来源:Program.cs

示例4: Index

        public ActionResult Index()
        {
            // Get most popular albums
            var albums = GetTopSellingAlbums(5);
            var albumCount = GetTotalAlbumns();

            Trace.Write(string.Format("Total number of Albums = {0} and Albums with 'The' = {1}", albumCount.Item1, albumCount.Item2));
            Trace.Write("Got top 5 albums");
            Trace.TraceWarning("Test TraceWarning;");
            Trace.IndentLevel++;
            Trace.TraceError("Test TraceError;");
            Trace.Write("Another trace line");
            Trace.IndentLevel++;
            Trace.Write("Yet another trace line");
            Trace.IndentLevel = 0;
            Trace.TraceInformation("Test TraceInformation;");

            HttpContext.Session["TestObject"] = new Artist { ArtistId = 123, Name = "Test Artist" };

            TraceSource ts = new TraceSource("Test source");

            ts.TraceEvent(TraceEventType.Warning, 0, string.Format("{0}: {1}", "trace", "source"));

            return View(albums);
        }
开发者ID:shiftkey,项目名称:Glimpse,代码行数:25,代码来源:HomeController.cs

示例5: UsesTraceSource

        public void UsesTraceSource()
        {
            Console.WriteLine("Config:"+ AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);

            Assert.AreEqual("FromAppConfig", ConfigurationManager.AppSettings["appConfigCheck"]);

            // just ensure, that <system.diagnostics> is configured for our test
            Trace.Refresh();
            TraceSource ts = new TraceSource("TraceLoggerTests", SourceLevels.All);
            Assert.AreEqual(1, ts.Listeners.Count);
            Assert.AreEqual(typeof(CapturingTraceListener), ts.Listeners[0].GetType());

            CapturingTraceListener.Events.Clear();
            ts.TraceEvent(TraceEventType.Information, 0, "message");
            Assert.AreEqual(TraceEventType.Information, CapturingTraceListener.Events[0].EventType);
            Assert.AreEqual("message", CapturingTraceListener.Events[0].FormattedMessage);

            // reset events and set loggerFactoryAdapter
            CapturingTraceListener.Events.Clear();
            NameValueCollection props = new NameValueCollection();
            props["useTraceSource"] = "TRUE";
            TraceLoggerFactoryAdapter adapter = new TraceLoggerFactoryAdapter(props);
            adapter.ShowDateTime = false;
            LogManager.Adapter = adapter;

            ILog log = LogManager.GetLogger("TraceLoggerTests");            
            log.WarnFormat("info {0}", "arg");
            Assert.AreEqual(TraceEventType.Warning, CapturingTraceListener.Events[0].EventType);
            Assert.AreEqual("[WARN]  TraceLoggerTests - info arg", CapturingTraceListener.Events[0].FormattedMessage);
        }
开发者ID:Rocketmakers,项目名称:common-logging,代码行数:30,代码来源:TraceLoggerTests.cs

示例6: WriteLog

        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="type"></param>
        /// <param name="id"></param>
        /// <param name="msg"></param>
        public static void WriteLog(TraceEventType type, int id, string msg)
        {
            string direct = HttpContext.Current.Server.MapPath("~/Log/Api/");
            if (!Directory.Exists(direct))
                Directory.CreateDirectory(direct);
            string file = direct + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";

            TextWriterTraceListener listen = new TextWriterTraceListener(file);
            listen.TraceOutputOptions = TraceOptions.ProcessId |
                                        TraceOptions.ThreadId |
                                        TraceOptions.Timestamp |
                                        TraceOptions.DateTime |
                                        TraceOptions.LogicalOperationStack;
                                        //TraceOptions.Callstack;

            Trace.Listeners.Add(listen);
            Trace.AutoFlush = false;
            //Trace.WriteLine("Test");

            SourceSwitch sourceSwitch = new SourceSwitch("sourceSwitch");
            sourceSwitch.Level = SourceLevels.Verbose;

            TraceSource traceSource = new TraceSource("traceSource");
            traceSource.Switch = sourceSwitch;
            traceSource.Listeners.Add(listen);

            traceSource.TraceEvent(type, id, msg);
            Trace.Close();
        }
开发者ID:yujianjob,项目名称:promotion,代码行数:35,代码来源:ApiTools.cs

示例7: ActivityNameForXmlListenersStrangeCharacters

        public void ActivityNameForXmlListenersStrangeCharacters()
        {
            TraceSource source = new TraceSource("testScopeSource");
            var listener = source.Listeners.OfType<TestTraceListener>().First();
            listener.MethodCallInformation.Clear();
            string transferIn = "TransferIn";
            string start = "<";
            string transferOut = "TransferOut";
            string stop = "Stopping...";
            var activityName = "<";

            using (var scope = new ActivityScope(source, 11, 12, 13, 14, transferIn, start, transferOut, stop, activityName))
            {
                source.TraceEvent(TraceEventType.Warning, 2, "B");
            }

            var events = listener.MethodCallInformation;
            StringAssert.StartsWith(events[0].Message, transferIn);

            Console.WriteLine(string.Join(",", events[1].Data));
            Assert.AreEqual(1, events[1].Data.Length);
            Assert.IsInstanceOfType(events[1].Data[0], typeof(XPathNavigator));
            var navigator = (XPathNavigator)events[1].Data[0];
            var resolver = new XmlNamespaceManager(navigator.NameTable);
            resolver.AddNamespace("ns1", "http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord");
            resolver.AddNamespace("ns2", "http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord");
            Assert.AreEqual(start, navigator.SelectSingleNode("/ns1:TraceRecord/ns1:Description", resolver).Value);
            Assert.AreEqual(activityName, navigator.SelectSingleNode("/ns1:TraceRecord/ns2:ExtendedData/ns2:ActivityName", resolver).Value);
            //StringAssert.Contains(events[1].Data[0].ToString(), activityName);
            //StringAssert.Contains(events[1].Data[0].ToString(), start);

            StringAssert.StartsWith(events[3].Message, transferOut);
            Assert.AreEqual(stop, events[4].Message);
        }
开发者ID:amccool,项目名称:essentialdiagnostics,代码行数:34,代码来源:ActivityScopeTests.cs

示例8: TraceLogger

 internal static Action<TraceEventType, Guid?, string, string> TraceLogger()
 {
     TraceSource _traceSource = new TraceSource("SikkerDigitalPost.Klient");
     return (severity, koversasjonsId, caller, message) =>
     {
         _traceSource.TraceEvent(severity, 1, "[{0}, {1}] {2}", koversasjonsId.GetValueOrDefault(), caller, message);
     };
 }
开发者ID:pereilif,项目名称:sikker-digital-post-klient-dotnet,代码行数:8,代码来源:Logging.cs

示例9: JustForTestingLoggingConfiguration

 public void JustForTestingLoggingConfiguration()
 {
     TraceSource traceSource = new TraceSource("DiagnosticsTracePerformanceTest");
     traceSource.TraceEvent(TraceEventType.Verbose, -1, "test trace info {0}", new MyTestObjectUnderTrace());
     //            Trace.TraceInformation("traced info");
     Trace.WriteLine("some message", "myCategory");
     Console.WriteLine("from console");
 }
开发者ID:Rocketmakers,项目名称:common-logging,代码行数:8,代码来源:PerformanceTests.cs

示例10: ConfigTest

        public void ConfigTest()
        {
            var source = new TraceSource("MSMQTEST", SourceLevels.All);

            source.TraceInformation("test1");

            source.TraceEvent(TraceEventType.Error, 1, "Test 2 {0}", 123);
        }
开发者ID:xsolon,项目名称:if,代码行数:8,代码来源:MsmqTraceListenerTests.cs

示例11: TraceSource

        public ActionResult TraceSource(string id)
        {
            HttpContext.Items.Add(IntegrationTestTab.Expected, id);

            var traceSource = new TraceSource("Test Source");
            traceSource.TraceEvent(TraceEventType.Warning, 0, id);

            return View(model: id);
        }
开发者ID:GitObjects,项目名称:Glimpse,代码行数:9,代码来源:TraceController.cs

示例12: TraceEvent

        public static void TraceEvent(TraceEventType type, string message)
        {
            TraceSource ts = new TraceSource(TraceSource);
            if (Trace.CorrelationManager.ActivityId == Guid.Empty)
            {
                Trace.CorrelationManager.ActivityId = Guid.NewGuid();
            }

            ts.TraceEvent(type, 0, message);
        }
开发者ID:IdentityModel,项目名称:Thinktecture.IdentityModel.v1,代码行数:10,代码来源:Tracing.cs

示例13: 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

示例14: 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

示例15: SetTraceSource

        /// <summary>
        /// Sets the trace source for all instances of <see cref="EFTracingConnection"/>.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="traceSource">The trace source to which to trace SQL command activity.</param>
        public static void SetTraceSource(this DbConnection connection, TraceSource traceSource)
        {
            Contract.Requires(connection != null);
            Contract.Requires(traceSource != null);

            foreach (var tracingConnection in connection.GetTracingConnections())
            {
                tracingConnection.CommandExecuting += (_, e) => traceSource.TraceInformation(e.ToFlattenedTraceString());
                tracingConnection.CommandFinished += (_, e) => traceSource.TraceInformation(e.ToFlattenedTraceString());
                tracingConnection.CommandFailed += (_, e) => traceSource.TraceEvent(TraceEventType.Error, 0, e.ToFlattenedTraceString());
            }
        }
开发者ID:jokingzhou,项目名称:AnJi-DevZoneGIS,代码行数:17,代码来源:EFTracingExtensionMethods.cs


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