本文整理汇总了C#中Watcher.Init方法的典型用法代码示例。如果您正苦于以下问题:C# Watcher.Init方法的具体用法?C# Watcher.Init怎么用?C# Watcher.Init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Watcher
的用法示例。
在下文中一共展示了Watcher.Init方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_handle_rolling_log
public void Can_handle_rolling_log()
{
var file = Path.Combine(".", "testfile2.xml");
if (File.Exists(file)) { File.Delete(file); }
File.WriteAllText(file, _buffer);
var outofbounds = new ConcurrentStack<OutOfBoundsEvent>();
var exceptionWhileReading = new ConcurrentStack<Exception>();
var files = new ConcurrentQueue<LogEntry>();
using (var watcher = new Watcher<LogEntry>(new FileWithPosition(file), new LogEntryParser()).Tap(w=>
{
w.LogEntry += l => { files.Enqueue(l); };
w.OutOfBounds += () => { outofbounds.Push(new OutOfBoundsEvent()); };
w.ExceptionOccurred += e => { exceptionWhileReading.Push(e); };
}))
{
watcher.Init();
File.WriteAllText(file, "");
Thread.Sleep(100/*750*3*/);
Assert.True(outofbounds.ToArray().Length >= 1, "outofbounds>=1");
}
}
示例2: Can_detect_changes_to_file
public void Can_detect_changes_to_file()
{
var file = Path.Combine(".", "testfile1.xml");
if (File.Exists(file)) { File.Delete(file); }
File.WriteAllText(file, _buffer);
var outofbounds = new ConcurrentStack<OutOfBoundsEvent>();
var exceptionWhileReading = new ConcurrentStack<Exception>();
var files = new ConcurrentQueue<LogEntry>();
using (var watcher = new Watcher<LogEntry>(new FileWithPosition(file),new LogEntryParser()).Tap(w=>
{
w.LogEntry += l => { files.Enqueue(l); };
w.OutOfBounds += () => { outofbounds.Push(new OutOfBoundsEvent()); };
w.ExceptionOccurred += e => { exceptionWhileReading.Push(e); };
}))
{
watcher.Init();
Assert.Equal(1, files.Count);
File.AppendAllText(file, _buffer);
Thread.Sleep(100/*750*3*/);
Assert.Equal(2, files.Count);
}
}