如何同步2 FileSystemWatcher的输出
本文关键字:FileSystemWatcher 输出 同步 何同步 | 更新日期: 2023-09-27 18:17:51
我已经实例化了2个FileSystemWatcher,我现在想要的是同步两个FileSystemWatcher。到目前为止,这里是一个日志输出示例:(注意格式的更改指的是另一个FSM,反之亦然)
Dec 15 15:28:19,8167876|: INFO |Web server call start_device_discovery() for: 10.191.20.0
Dec 15 15:28:19,8167876|: START | Device discovery started for: 10.191.20.0
Dec 15 15:28:19,9261472|: INFO |Discovery is active for: NET_10.191.20.0_24
Dec 15 15:28:20,1136208|: INFO |Device discovered from NET_10.191.20.0_24 BaseModelName: "TASKalfa 250ci", ModelName: "TASKalfa 250ci", MoName: "TASKalfa 250ci"
Dec 15 15:28:20,3948312|: INFO |Device discovered from NET_10.191.20.0_24 BaseModelName: "FS-C2626MFP", ModelName: "FS-C2626MFP", MoName: "FS-C2626MFP"
Dec 15 15:28:20,4260768|: INFO |Device discovered from NET_10.191.20.0_24 BaseModelName: "FS-3640MFP", ModelName: "FS-3640MFP", MoName: "FS-3640MFP"
Dec 15 15:28:20,5198136|: INFO |Device discovered from NET_10.191.20.0_24 BaseModelName: "TASKalfa 7550ci", ModelName: "TASKalfa 7550ci", MoName: "TASKalfa 7550ci"
Dec 15 15:28:20,6135504|: INFO |Device discovered from NET_10.191.20.0_24 BaseModelName: "FS-C2626MFP", ModelName: "FS-C2626MFP", MoName: "FS-C2626MFP"
2011-12-15 15:28:19,785| INFO | NetworkList - setStartDiscovery - Starting point
2011-12-15 15:28:19,785| INFO | NetActionProvider - performAction - JYR
2011-12-15 15:28:19,785| INFO | NetActionProvider - ATN_DISCOVERY_START
2011-12-15 15:28:19,785| INFO | SNMPDiscovery - Starting discovery for NET_10.191.20.0_24.
请密切关注他们的时间。在15:28:19,8167876ms之前第一次输出的语句
Dec 15 15:28:19,8167876|: INFO |Web server call start_device_discovery() for: 10.191.20.0
2011-12-15 15:28:19,785| INFO | NetworkList - setStartDiscovery - Starting point
我想做的是尝试同步这两个观察者。什么好主意吗?谢谢。
您可以尝试同步日志访问。为此,需要一个简单的对象进行同步,所有FileSystemWatcher
事件处理程序都可以访问该对象。为了简化,您可以使用logger对象(但请阅读此处的注释部分)。一旦FileSystemWatcher
收到通知,立即获取锁:
private static void OnChanged(object source, FileSystemEventArgs e)
{
lock(MyLogger)
{
MyLogger.Log("something changed");
}
}