/// <summary> /// Creates an event listener that logs using a <see cref="LogglySink" />. /// </summary> /// <param name="instanceName">The name of the instance originating the entries.</param> /// <param name="connectionString">The endpoint address for the Loggly Service.</param> /// <param name="customerToken">The loggly customerToken that must be part of the Url.</param> /// <param name="tag">The tag used in loggly updates. Default is to use the instanceName.</param> /// <param name="flattenPayload">Flatten the payload if you want the parameters serialized.</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 Loggly 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="LogglySink" /> to log events. /// </returns> public static EventListener CreateListener(string instanceName, string connectionString, string customerToken, string tag, bool flattenPayload, TimeSpan? bufferingInterval = null, TimeSpan? listenerDisposeTimeout = null, int maxBufferSize = Buffering.DefaultMaxBufferSize) { var listener = new ObservableEventListener(); listener.LogToLoggly(instanceName, connectionString, customerToken, tag, flattenPayload, bufferingInterval, listenerDisposeTimeout, maxBufferSize); return listener; }
/// <summary> /// Creates an event listener that logs using a <see cref="LogglySink" />. /// </summary> /// <param name="instanceName">The name of the instance originating the entries.</param> /// <param name="connectionString">The endpoint address for the Loggly Service.</param> /// <param name="customerToken">The loggly customerToken that must be part of the Url.</param> /// <param name="tag">The tag used in loggly updates. Default is to use the instanceName.</param> /// <param name="flattenPayload">Flatten the payload if you want the parameters serialized.</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 Loggly 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="LogglySink" /> to log events. /// </returns> public static EventListener CreateListener(string instanceName, string connectionString, string customerToken, string tag, bool flattenPayload, TimeSpan?bufferingInterval = null, TimeSpan?listenerDisposeTimeout = null, int maxBufferSize = Buffering.DefaultMaxBufferSize) { var listener = new ObservableEventListener(); listener.LogToLoggly(instanceName, connectionString, customerToken, tag, flattenPayload, bufferingInterval, listenerDisposeTimeout, maxBufferSize); return(listener); }
static void Main(string[] args) { /** * Setup for in-process logging. Do it once for the application setup. */ var listener1 = new ObservableEventListener(); listener1.EnableEvents( LogEventSource.Log, EventLevel.LogAlways, LogEventSource.Keywords.Perf | LogEventSource.Keywords.Diagnostic); // When setting up the the listener we can override the default values for buffering. Default values are recommended unless you are testing or have specific needs. var sinkSubscription = listener1.LogToLoggly("TestInstance", "https://logs-01.loggly.com", "[Loggly customer token]", "LogglyTest", TimeSpan.FromMinutes(1), null, 5, 1000); /** * Do some logging ... */ Console.WriteLine("Start..."); // Log startup event ... LogEventSource.Log.Startup(); // Log some fake failures ... for (int i = 0; i < 2; i++) { LogEventSource.Log.Failure("fail!!!"); Thread.Sleep(500); } /** * Dispose or flush the sink at the end of the process when using in-process logging. * Otherwise, you could lose logging data. * Default settings will flush the buffer at 10 minute intervals or when buffering count is reached, i.e. 1000. */ sinkSubscription.Sink.FlushAsync(); Console.WriteLine("Press any key to quit."); Console.ReadKey(); }