Пример #1
0
            public static void Run()
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();

                var cts = new CancellationTokenSource();

                var subscription = ObservableEventListener.FromEventSource(MyEventSource.Log)
                                   .Buffer(TimeSpan.FromSeconds(5), 1000, cts.Token)
                                   //.TakeUntil(cts.Token)
                                   .LogToFile("mytest.txt", x => DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss,fff") + " " + "Info " + x.Payload[0], Encoding.UTF8, false);
                //.LogToRollingFlatFile((dt, count) => $"test{count}.txt", dt => "", 4000,
                //                  x => DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss,fff") + " " + "Info " + x.Payload[0], Encoding.UTF8, false);

                var sw = Stopwatch.StartNew();

                for (int i = 0; i < 100000; i++)
                {
                    loggger.Info(Guid.NewGuid().ToString());
                }
                Console.WriteLine("come here:" + sw.Elapsed.TotalMilliseconds);

                cts.Cancel();
                subscription.Dispose();

                Console.WriteLine("after wait:" + sw.Elapsed.TotalMilliseconds);
                sw.Stop();
                Console.WriteLine("time: " + sw.Elapsed.TotalMilliseconds + "ms");
                // line / elapsed
                Console.WriteLine(((double)100000 / sw.Elapsed.TotalMilliseconds) + "ms");
            }
Пример #2
0
        static void Main(string[] args)
        {
            ObservableEventListener.FromEventSource(MyEventSource.Log).LogToConsole();


            //MyEventSource.Log.Info("hogehoge");
            MyEventSource.Log.Write("Check", new { uid = 100 });


            Console.ReadLine();

            //EtwStream.RollCheck();

            //EtwStream.Test2();


            //Console.WriteLine("EtwStream");
            //EtwStream.Run();

            //Console.WriteLine("NLog");
            //NLoog.Run();

            //Console.WriteLine("Slab");
            //Slab.Run();


            //Console.WriteLine("Serilooog");
            //Serilooog.Run();
            ////EtwStream.Test();
        }
Пример #3
0
            public static void RollCheck()
            {
                var cts = new CancellationTokenSource();
                var d   = ObservableEventListener.FromEventSource(MyEventSource.Log)
                          .Buffer(TimeSpan.FromSeconds(5), 100, cts.Token)
                          //.LogToFile("hoge.txt", x => (string)x.Payload[0], Encoding.UTF8, false);
                          .LogToRollingFile((dt, i) => $@"EtwStreamLog\RollingCheck{dt.ToString("yyyyMMdd")}.{i.ToString("00")}.log", x => x.ToString("yyyyMMdd"), 1000, x => x.DumpPayloadOrMessage(), Encoding.UTF8, true);
                var sw = new Stopwatch();

                sw.Start();
                Task.WhenAll(Enumerable.Range(0, 100)
                             .Select(async(i) =>
                {
                    foreach (var j in Enumerable.Range(0, 10000))
                    {
                        await Task.Run(() =>
                        {
                            MyEventSource.Log.Info($"abc{i}:{j}");
                        });
                    }
                }))
                .Wait();

                cts.Cancel();
                d.Dispose();

                sw.Stop();
                Console.WriteLine("elapsed {0}", sw.Elapsed);
            }
Пример #4
0
            public static void Test()
            {
                var cts = new CancellationTokenSource();

                var subscription = ObservableEventListener.FromEventSource(MyEventSource.Log)
                                   .Buffer(TimeSpan.FromSeconds(5), 1000, cts.Token)
                                   .LogToFile("etw.txt", x => DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss,fff") + " " + "Info " + x.Payload[0], Encoding.UTF8, true);

                loggger.Info("aiueo");
                loggger.Info("kakikukeko");

                Console.WriteLine("waiting...");
                Console.ReadLine();
                cts.Cancel();
                subscription.Dispose();
            }
Пример #5
0
        static public TelemetryPipe CollectEventSourceEvents(this TelemetryPipe pipe, IEnumerable <ETWProvider> providers, Dictionary <string, string> additionalProperties = null)
        {
            foreach (var provider in providers)
            {
                pipe.RegisterObserver(ObservableEventListener
                                      .FromEventSource(provider.Name, provider.Level)
                                      .Select(ev => new TelemetryEvent()
                {
                    Type            = "event",
                    Data            = FromEventSourceEvent(ev, additionalProperties),
                    PublishDateTime = DateTime.UtcNow
                }));
            }


            return(pipe);
        }
Пример #6
0
        static void Main(string[] args)
        {
            // var source = ObservableEventListener.FromTraceEvent("SampleEventSource", "LoggerEventSource").Publish().RefCount();
            var source = ObservableEventListener.FromEventSource(SampleEventSource.Log);

            source.Subscribe(x => Console.WriteLine(x.DumpPayloadOrMessage()));

            // var providingIndex = 0;
            var providingMessages = new[]
            {
                "1:Hello EtwStream",
                "2:Now LINQPad is ETW viewer",
                "3:Logs are Event Stream",
                "4:Everything can compose by Rx",
                "5:EventSource is...",
                "6:Best practice for logging on .NET",
                "1:Hello EtwStream",
                "2:Now LINQPad is ETW viewer",
                "3:Logs are Event Stream",
                "4:Everything can compose by Rx",
                "5:EventSource is...",
                "6:Best practice for logging on .NET",
            };

            Console.WriteLine("1~6:msg");
            // var i = 0;
            while (true)
            {
                // LoggerEventSource.Log.Write("start new event", new { count = i++ });

                var measure = LoggerEventSource.Log.MeasureExecution("Readtime");

                var msg = Console.ReadLine();

                // Thread.Sleep(TimeSpan.FromSeconds(1));
                //var msg = providingMessages[providingIndex++];
                if (msg == null)
                {
                    return;
                }

                var split   = msg.Split(':');
                var id      = int.Parse(split[0]);
                var message = (split.Length == 2 && split[1] != "")
                    ? split[1]
                    : null;

                measure.Dispose();
                switch (id)
                {
                case 1:
                    SampleEventSource.Log.LogAlways(message ?? "LogAlways");
                    break;

                case 2:
                    SampleEventSource.Log.Critical(message ?? "Critical");
                    break;

                case 3:
                    SampleEventSource.Log.Error(message ?? "Error");
                    break;

                case 4:
                    SampleEventSource.Log.Warning(message ?? "Warning");
                    break;

                case 5:
                    SampleEventSource.Log.Informational(message ?? "Informational");
                    break;

                case 6:
                    SampleEventSource.Log.Verbose(message ?? "Verbose");
                    break;

                default:
                    break;
                }
            }
        }