本文整理汇总了C#中ObservableEventListener类的典型用法代码示例。如果您正苦于以下问题:C# ObservableEventListener类的具体用法?C# ObservableEventListener怎么用?C# ObservableEventListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObservableEventListener类属于命名空间,在下文中一共展示了ObservableEventListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestEventSink
public async Task TestEventSink()
{
var listener = new TcpListener(IPAddress.Loopback, 0);
listener.Start();
int port = ((IPEndPoint)listener.Server.LocalEndPoint).Port;
var slabListener = new ObservableEventListener();
slabListener.Subscribe(new TcpEventSink(IPAddress.Loopback, port,
new ExponentialBackoffTcpReconnectionPolicy(),
new TestEventFormatter()));
var source = TestEventSource.GetInstance();
slabListener.EnableEvents(source, EventLevel.LogAlways, Keywords.All);
var listenerClient = await listener.AcceptTcpClientAsync();
source.Message("Boris", "Meep");
var receiverReader = new StreamReader(listenerClient.GetStream());
var line = await receiverReader.ReadLineAsync();
Assert.Equal(
"EventId=1 EventName=MessageInfo Level=Error \"FormattedMessage=Meep - Boris\" \"message=Boris\" \"caller=Meep\"",
line);
listenerClient.Close();
listener.Stop();
slabListener.Dispose();
}
示例2: EnableLoggingListener
private void EnableLoggingListener()
{
listener = new ObservableEventListener();
listener.LogToWindowsAzureTable("CustomEvents", "DefaultEndpointsProtocol=https;AccountName=musiccloudstorage;AccountKey=...");
//listener.EnableEvents(AuditEvent.Log, EventLevel.LogAlways, Keywords.All);
listener.EnableEvents(ErrorEvent.Log, EventLevel.LogAlways, Keywords.All);
}
示例3: UnderReleaseBufferLeak
public void UnderReleaseBufferLeak()
{
ResourceLeakDetector.DetectionLevel preservedLevel = ResourceLeakDetector.Level;
try
{
ResourceLeakDetector.Level = ResourceLeakDetector.DetectionLevel.Paranoid;
var eventListener = new ObservableEventListener();
Mock<IObserver<EventEntry>> logListener = this.mockRepo.Create<IObserver<EventEntry>>();
var eventTextFormatter = new EventTextFormatter();
Func<EventEntry, bool> leakPredicate = y => y.TryFormatAsString(eventTextFormatter).Contains("LEAK");
logListener.Setup(x => x.OnNext(It.Is<EventEntry>(y => leakPredicate(y)))).Verifiable();
logListener.Setup(x => x.OnNext(It.Is<EventEntry>(y => !leakPredicate(y))));
eventListener.Subscribe(logListener.Object);
eventListener.EnableEvents(DefaultEventSource.Log, EventLevel.Verbose);
this.CreateAndForgetBuffer();
GC.Collect();
GC.WaitForPendingFinalizers();
this.mockRepo.Verify();
}
finally
{
ResourceLeakDetector.Level = preservedLevel;
}
}
示例4: Start
public void Start(TflProcess process) {
if (_started)
return;
_started = true;
Name = process.Name;
foreach (var log in process.Log) {
switch (log.Provider) {
case "file":
log.Folder = log.Folder.Replace('/', '\\');
log.File = log.File.Replace('/', '\\');
log.Folder = (log.Folder.Equals(Common.DefaultValue) ? "logs" : log.Folder).TrimEnd('\\') + "\\";
log.File = (log.File.Equals(Common.DefaultValue) ? "tfl-" + process.Name + ".log" : log.File).TrimStart('\\');
var fileListener = new ObservableEventListener();
fileListener.EnableEvents(TflEventSource.Log, (EventLevel)Enum.Parse(typeof(EventLevel), log.Level));
SinkSubscriptions.Add(fileListener.LogToRollingFlatFile(log.Folder + log.File, 5000, "yyyy-MM-dd", RollFileExistsBehavior.Increment, RollInterval.Day, new LegacyLogFormatter(), 0, log.Async));
EventListeners.Add(fileListener);
break;
case "mail":
if (log.Subject.Equals(Common.DefaultValue)) {
log.Subject = process.Name + " " + log.Level;
}
var mailListener = new ObservableEventListener();
mailListener.EnableEvents(TflEventSource.Log, EventLevel.Error);
SinkSubscriptions.Add(mailListener.LogToEmail(log));
EventListeners.Add(mailListener);
break;
}
}
}
示例5: With1Listener
public static void With1Listener(IEnumerable<EventSource> loggers, Action<ObservableEventListener, InMemoryEventListener> scenario)
{
using (var errorsListener = new InMemoryEventListener())
using (var listener = new ObservableEventListener())
{
try
{
errorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Verbose, Keywords.All);
scenario(listener, errorsListener);
}
finally
{
foreach (var logger in loggers)
{
try
{ listener.DisableEvents(logger); }
catch
{ }
}
errorsListener.DisableEvents(SemanticLoggingEventSource.Log);
}
}
}
示例6: SetUp
public void SetUp()
{
AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory);
this.fileName = Path.ChangeExtension(Guid.NewGuid().ToString("N"), ".log");
this.eventTextFormatter = new EventTextFormatter(EventTextFormatter.DashSeparator);
this.listener = new ObservableEventListener();
}
示例7: TestExporter
public void TestExporter() {
var listener = new ObservableEventListener();
listener.EnableEvents(TflEventSource.Log, EventLevel.Verbose);
var subscription = listener.LogToConsole(new LegacyLogFormatter());
var file = Path.GetTempFileName();
File.WriteAllText(file, @"t1,t2,t3,t4
Monday,10,1.1,1/1/2014
Tuesday,11,2.2,2/1/2014
Wednesday,12,3.3,3/1/2014
Wednesday,12,3.3,3/1/2014
Thursday,13,4.4,4/1/2014
Friday,14,5.5,5/1/2014
Saturday,15,6.6,6/1/2014");
File.Delete(OUTPUT);
var profile = new Profiler().Profile(file);
new ProfileExporter().Export(profile, OUTPUT);
subscription.Dispose();
listener.DisableEvents(TflEventSource.Log);
listener.Dispose();
Assert.IsTrue(File.Exists(OUTPUT));
}
示例8: TestBase
protected TestBase(ITestOutputHelper output)
{
this.Output = output;
this.eventListener = new ObservableEventListener();
this.eventListener.LogToTestOutput(output);
this.eventListener.EnableEvents(DefaultEventSource.Log, EventLevel.Verbose);
}
示例9: Initialize
public override void Initialize()
{
var eventListener = new ObservableEventListener();
eventListener.EnableEvents(
VirtoCommerceEventSource.Log,
EventLevel.LogAlways,
Keywords.All);
var assetsConnection = ConfigurationManager.ConnectionStrings["AssetsConnectionString"];
if (assetsConnection != null)
{
var properties = assetsConnection.ConnectionString.ToDictionary(";", "=");
var provider = properties["provider"];
var assetsConnectionString = properties.ToString(";", "=", "provider");
if (string.Equals(provider, FileSystemBlobProvider.ProviderName, StringComparison.OrdinalIgnoreCase))
{
eventListener.LogToRollingFlatFile("AvaTax.log",
10000,
"hh",
RollFileExistsBehavior.Increment,
RollInterval.Day);
}
else
if (string.Equals(provider, AzureBlobProvider.ProviderName, StringComparison.OrdinalIgnoreCase))
{
eventListener.LogToWindowsAzureTable(
"VirtoCommerce2", assetsConnectionString);
}
}
var settingsManager = _container.Resolve<ISettingsManager>();
var avalaraTax = new AvaTaxSettings(_usernamePropertyName, _passwordPropertyName, _serviceUrlPropertyName, _companyCodePropertyName, _isEnabledPropertyName, _isValidateAddressPropertyName, settingsManager);
_container.RegisterType<AvaTaxController>
(new InjectionConstructor(
avalaraTax));
_container.RegisterInstance<ITaxSettings>(avalaraTax);
//Subscribe to cart changes. Calculate taxes
_container.RegisterType<IObserver<CartChangeEvent>, CalculateCartTaxesObserver>("CalculateCartTaxesObserver");
//Subscribe to order changes. Calculate taxes
_container.RegisterType<IObserver<OrderChangeEvent>, CalculateOrderTaxesObserver>("CalculateOrderTaxesObserver");
//Subscribe to order changes. Calculate taxes
_container.RegisterType<IObserver<OrderChangeEvent>, CancelOrderTaxesObserver>("CancelOrderTaxesObserver");
//Subscribe to order changes. Adjust taxes
_container.RegisterType<IObserver<OrderChangeEvent>, CalculateTaxAdjustmentObserver>("CalculateTaxAdjustmentObserver");
}
示例10: RegisterEFLogger
private static void RegisterEFLogger()
{
var listener = new ObservableEventListener();
listener.EnableEvents(EFLogging.Logger, EventLevel.LogAlways, Keywords.All);
listener.LogToFlatFile("EFSqls.log");
listener.LogToWindowsAzureTable(instanceName: "Protiviti", connectionString: "UseDevelopmentStorage=true",tableAddress:"EFSqls");
}
示例11: CreateListener
/// <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;
}
示例12: TestBase
/// <summary>
/// Initializes a new instance of the <see cref="TestBase" /> class.
/// </summary>
protected TestBase()
{
var observableEventListener = new ObservableEventListener();
observableEventListener.EnableEvents(ExceptionLoggingEventSource.Log, EventLevel.LogAlways);
observableEventListener.LogToConsole();
}
示例13: 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;
}
示例14: RegisterLogger
private static void RegisterLogger()
{
var listener = new ObservableEventListener();
listener.EnableEvents(WebApiTracing.Log, EventLevel.LogAlways, Keywords.All);
listener.LogToConsole();
listener.LogToFlatFile("test.log");
listener.LogToWindowsAzureTable(instanceName: "Protiviti", connectionString: "UseDevelopmentStorage=true");
}
示例15: Main
static void Main(string[] args)
{
// optimizing IOCP performance
int minWorkerThreads;
int minCompletionPortThreads;
ThreadPool.GetMinThreads(out minWorkerThreads, out minCompletionPortThreads);
ThreadPool.SetMinThreads(minWorkerThreads, Math.Max(16, minCompletionPortThreads));
int threadCount = Environment.ProcessorCount;
if (args.Length > 0)
{
threadCount = int.Parse(args[0]);
}
var eventListener = new ObservableEventListener();
eventListener.LogToConsole();
eventListener.EnableEvents(BootstrapperEventSource.Log, EventLevel.Verbose);
eventListener.EnableEvents(MqttIotHubAdapterEventSource.Log, EventLevel.Verbose);
eventListener.EnableEvents(ChannelEventSource.Log, EventLevel.Verbose);
eventListener.EnableEvents(BootstrapEventSource.Log, EventLevel.Verbose);
eventListener.EnableEvents(ExecutorEventSource.Log, EventLevel.Verbose);
eventListener.EnableEvents(MqttEventSource.Log, EventLevel.Verbose);
try
{
var cts = new CancellationTokenSource();
var certificate = new X509Certificate2("protocol-gateway.contoso.com.pfx", "password");
var settingsProvider = new AppConfigSettingsProvider();
BlobSessionStatePersistenceProvider blobSessionStateProvider = BlobSessionStatePersistenceProvider.CreateAsync(
settingsProvider.GetSetting("BlobSessionStatePersistenceProvider.StorageConnectionString"),
settingsProvider.GetSetting("BlobSessionStatePersistenceProvider.StorageContainerName")).Result;
TableQos2StatePersistenceProvider tableQos2StateProvider = TableQos2StatePersistenceProvider.CreateAsync(
settingsProvider.GetSetting("TableQos2StatePersistenceProvider.StorageConnectionString"),
settingsProvider.GetSetting("TableQos2StatePersistenceProvider.StorageTableName")).Result;
var bootstrapper = new Bootstrapper(settingsProvider, blobSessionStateProvider, tableQos2StateProvider);
Task.Run(() => bootstrapper.RunAsync(certificate, threadCount, cts.Token), cts.Token);
while (true)
{
string input = Console.ReadLine();
if (input != null && input.ToLowerInvariant() == "exit")
{
break;
}
}
cts.Cancel();
bootstrapper.CloseCompletion.Wait(TimeSpan.FromSeconds(20));
}
finally
{
eventListener.Dispose();
}
}