示例#1
0
 /// <summary>
 /// Creates an event listener that logs using a <see cref="ElasticsearchSink" />.
 /// </summary>
 /// <param name="instanceName">The name of the instance originating the entries.</param>
 /// <param name="connectionString">The endpoint address for the Elasticsearch Service.</param>
 /// <param name="index">Index name prefix formatted as index-{0:yyyy.MM.DD}</param>
 /// <param name="type">The Elasticsearch entry type</param>
 /// <param name="flattenPayload">Flatten the payload collection when serializing event entries</param>
 /// <param name="bufferingInterval">The buffering interval between each batch publishing.</param>
 /// <param name="listenerDisposeTimeout">Defines a timeout interval for the flush operation when the listener is disposed.</param>
 /// <param name="maxBufferSize">The maximum number of entries that can be buffered while it's sending to Elasticsearch before the sink starts dropping entries.
 /// This means that if the timeout period elapses, some event entries will be dropped and not sent to the store. Calling <see cref="IDisposable.Dispose" /> on
 /// the <see cref="EventListener" /> will block until all the entries are flushed or the interval elapses.
 /// If <see langword="null" /> is specified, then the call will block indefinitely until the flush operation finishes.</param>
 /// <returns>
 /// An event listener that uses <see cref="ElasticsearchSink" /> to log events.
 /// </returns>
 public static EventListener CreateListener(string instanceName, string connectionString, string index, string type, bool flattenPayload = true,
     TimeSpan? bufferingInterval = null, TimeSpan? listenerDisposeTimeout = null, int maxBufferSize = Buffering.DefaultMaxBufferSize)
 {
     var listener = new ObservableEventListener();
     listener.LogToElasticsearch(instanceName, connectionString, index, type, flattenPayload, bufferingInterval,
         listenerDisposeTimeout, maxBufferSize);
     return listener;
 }
示例#2
0
        /// <summary>
        /// Creates an event listener that logs using a <see cref="ElasticsearchSink" />.
        /// </summary>
        /// <param name="instanceName">The name of the instance originating the entries.</param>
        /// <param name="connectionString">The endpoint address for the Elasticsearch Service.</param>
        /// <param name="index">Index name prefix formatted as index-{0:yyyy.MM.DD}</param>
        /// <param name="type">The Elasticsearch entry type</param>
        /// <param name="flattenPayload">Flatten the payload collection when serializing event entries</param>
        /// <param name="bufferingInterval">The buffering interval between each batch publishing.</param>
        /// <param name="listenerDisposeTimeout">Defines a timeout interval for the flush operation when the listener is disposed.</param>
        /// <param name="maxBufferSize">The maximum number of entries that can be buffered while it's sending to Elasticsearch before the sink starts dropping entries.
        /// This means that if the timeout period elapses, some event entries will be dropped and not sent to the store. Calling <see cref="IDisposable.Dispose" /> on
        /// the <see cref="EventListener" /> will block until all the entries are flushed or the interval elapses.
        /// If <see langword="null" /> is specified, then the call will block indefinitely until the flush operation finishes.</param>
        /// <returns>
        /// An event listener that uses <see cref="ElasticsearchSink" /> to log events.
        /// </returns>
        public static EventListener CreateListener(string instanceName, string connectionString, string index, string type, bool flattenPayload = true,
                                                   TimeSpan?bufferingInterval = null, TimeSpan?listenerDisposeTimeout = null, int maxBufferSize = Buffering.DefaultMaxBufferSize)
        {
            var listener = new ObservableEventListener();

            listener.LogToElasticsearch(instanceName, connectionString, index, type, flattenPayload, bufferingInterval,
                                        listenerDisposeTimeout, maxBufferSize);
            return(listener);
        }
        public void then_try_write_using_event_source()
        {
            SimpleEventSource       ses      = new SimpleEventSource();
            ObservableEventListener listener = new ObservableEventListener();

            using (listener)
            {
                listener.EnableEvents(ses, EventLevel.LogAlways, EventKeywords.All);
                listener.LogToElasticsearch(Environment.MachineName, this.elasticsearchUrl, "slabqwe-{0:yyyy.MM}", "etw");

                ses.MyEvent1("qwe1", 2);
            }
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);


            var listener = new ObservableEventListener();
            listener.EnableEvents(TestEvents.Log, EventLevel.LogAlways, Keywords.All);

            listener.LogToConsole();
            listener.LogToElasticsearch("SLABEL", "http://localhost:9200", "myindex", "mytype", bufferingCount: 1);

            TestEvents.Log.Critical("Hello world In-Process Critical");
            TestEvents.Log.Error("Hello world In-Process Error");
            TestEvents.Log.Informational("Hello world In-Process Informational");
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);


            var listener = new ObservableEventListener();

            listener.EnableEvents(TestEvents.Log, EventLevel.LogAlways, Keywords.All);

            listener.LogToConsole();
            listener.LogToElasticsearch("SLABEL", "http://localhost:9200", "myindex", "mytype", bufferingCount: 1);

            TestEvents.Log.Critical("Hello world In-Process Critical");
            TestEvents.Log.Error("Hello world In-Process Error");
            TestEvents.Log.Informational("Hello world In-Process Informational");
        }