本文整理汇总了C#中ObservableEventListener.LogToLoggly方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableEventListener.LogToLoggly方法的具体用法?C# ObservableEventListener.LogToLoggly怎么用?C# ObservableEventListener.LogToLoggly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableEventListener
的用法示例。
在下文中一共展示了ObservableEventListener.LogToLoggly方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateListener
/// <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;
}
示例2: Main
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();
}