本文整理汇总了C#中ObservableEventListener.LogToSqlDatabase方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableEventListener.LogToSqlDatabase方法的具体用法?C# ObservableEventListener.LogToSqlDatabase怎么用?C# ObservableEventListener.LogToSqlDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableEventListener
的用法示例。
在下文中一共展示了ObservableEventListener.LogToSqlDatabase方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateListener
/// <summary>
/// Subscribes to the listener using a <see cref="SqlDatabaseSink" />.
/// </summary>
/// <param name="instanceName">The name of the instance originating the entries.</param>
/// <param name="connectionString">The connection string.</param>
/// <param name="tableName">The name of the table.</param>
/// <param name="bufferingInterval">The buffering interval between each batch publishing.</param>
/// <param name="bufferingCount">The number of entries that will trigger a batch publishing.</param>
/// <param name="listenerDisposeTimeout">Defines a timeout interval for the flush operation when the listener is disposed.
/// 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>
/// <param name="maxBufferSize">The maximum number of entries that can be buffered while it's sending to Windows Azure Storage 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. Normally, calling <see cref="IDisposable.Dispose" /> on
/// the <see cref="System.Diagnostics.Tracing.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="SqlDatabaseSink"/> to log events.</returns>
public static EventListener CreateListener(string instanceName, string connectionString, string tableName = DefaultTableName, TimeSpan? bufferingInterval = null, int bufferingCount = Buffering.DefaultBufferingCount, TimeSpan? listenerDisposeTimeout = null, int maxBufferSize = Buffering.DefaultMaxBufferSize)
{
var listener = new ObservableEventListener();
listener.LogToSqlDatabase(instanceName, connectionString, tableName, bufferingInterval, bufferingCount, listenerDisposeTimeout, maxBufferSize);
return listener;
}
示例2: MultipleEventListenersKeywords
static void MultipleEventListenersKeywords()
{
var listener1 = new ObservableEventListener();
var listener2 = new ObservableEventListener();
listener1.EnableEvents(MyCompanyEventSource.Log, EventLevel.LogAlways, MyCompanyEventSource.Keywords.Perf | MyCompanyEventSource.Keywords.Diagnostic);
listener2.EnableEvents(MyCompanyEventSource.Log, EventLevel.LogAlways, Keywords.All);
// Set up and enable the event listeners - typically done when the application starts
listener1.LogToConsole();
// The SinkSubscription is used later to flush the buffer
var subscription = listener2.LogToSqlDatabase("Demo Semantic Logging Instance", connectionString);
// Log some messages
MyCompanyEventSource.Log.PageStart(23, "http://mysite/demopage");
MyCompanyEventSource.Log.Startup();
MyCompanyEventSource.Log.Failure("Couldn't connect to server.");
Console.WriteLine("Written three log messages.\nUsing a basic console listener and a SQL listener to capture them.");
Console.WriteLine("Only the messages with the Perf or Diagnostic keywords appears in the console, \nall three appear in the SQL Database:\n");
// Disable the event listener - typically done when the application terminates
listener1.DisableEvents(MyCompanyEventSource.Log);
listener2.DisableEvents(MyCompanyEventSource.Log);
// Manually flush the buffer so you can see what's in the database
subscription.Sink.FlushAsync().Wait();
ShowContentsOfSqlDatabaseTable();
listener1.Dispose();
listener2.Dispose();
}