[.NET] - EventLog.EntryWritten Event
刚看到在MSND论坛上有人问一个EventLog.EntryWritten Event相关的问题,说是在2015触发了一个2013年的EventWritten的事件,比较好奇,然后查看了下这个类:
https://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.entrywritten%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
在的Remarks里看到有这么一段话:
The system responds to WriteEntry only if the last write event occurred at least six seconds previously. This implies you will only receive one EntryWritten event notification within a six-second interval, even if more than one event log change occurs. If you insert a sufficiently long sleep interval (around 10 seconds) between calls to WriteEntry, you are less likely to miss an event. However, if write events occur more frequently, you might not recieve the event notification until the next interval. Typically, missed event notifications are not lost, but delayed.
意思大概是这个时间只会在6秒内触发一次,如何将两次调用WriteEntry的时间间隔大于6s,那就不会造成事件miss,只是会被延迟。写了一个程序来测试下:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace P20150409
{
class Program
{
static void Main(string[] args)
{
EventLog myNewLog = new EventLog("Application", ".", "dotNET Sample App"); myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten);
myNewLog.EnableRaisingEvents = true;
while (true)
{
System.Threading.Thread.Sleep(3000);
string EventWriteTime = DateTime.Now.ToString();
Console.WriteLine("Log is written at" + EventWriteTime);
myNewLog.WriteEntry("Test message written at" + EventWriteTime + " " + System.Threading.Thread.CurrentThread.ManagedThreadId, EventLogEntryType.Information);
Console.WriteLine();
}
Console.ReadLine();
} private static void MyOnEntryWritten(object sender, EntryWrittenEventArgs e)
{
System.Threading.Thread.Sleep(6000);
Console.WriteLine("EntryWritten event is fired at" + DateTime.Now.ToString());
Console.WriteLine("Log time is" + e.Entry.Message);
Console.WriteLine();
}
}
}
以下是输出结果:

可以看到事件确实是没有被miss,而且触发的那次call EntryWrite方法与当前call EntryWrite的时间间隔越来越大,也就是说,这是有可能在两年后触发该事件。。。):
但是在把事件里的线程睡眠代码去掉后,事件是实时触发的,所谓的6s时间间隔内的限制并没有体现出来,不知道是不是测试的方式不对,还是系统的设置问题。如各位有知道,请指导下。
[.NET] - EventLog.EntryWritten Event的更多相关文章
- PowerShell_零基础自学课程_8_高级主题:WMI对象和COM组件
本系列文章从最初的初识开始,基本上可以完成一些简单的系统管理了,为了更方便的管理系统,同时为了更好的发掘系统的性能,就需要用到系统提供 的一些高级特性,在Windows Server系列的OS中,如果 ...
- Win7 服务优化个人单机版
我的PC设备比较旧了,为了系统能流畅点,不必要的服务就不开启了.然而,服务那么多,每次重装,都要从头了解一下一边,浪费时间. 个人在网络上收集信息并结合自己的摸索,整理如下,以备查找. 服务名称 显 ...
- python开发者框架套件总结: package 包 frameworks
python开发者的package 包 框架套件总结: frameworks 开发环境: anaconda pycharm django awesome-django : 介绍 django ...
- jQuery 实战读书笔记之第六章:事件本质
理解浏览器事件模型 understandEventModel.html 代码: <!DOCTYPE HTML> <html> <head> <title> ...
- onload;readystatechange;DOMContentLoaded事件
当文档的 readyState 属性发生改变时,会触发 readystatechange 事件. onload 事件会在页面或图像加载完成后立即发生 当纯HTML被完全加载以及解析时,DOMConte ...
- .NET Core的日志[4]:将日志写入EventLog
面向Windows的编程人员应该不会对Event Log感到陌生,以至于很多人提到日志,首先想到的就是EventLog.EventLog不仅仅记录了Windows系统自身针对各种事件的日志,我们的应用 ...
- 服务器重启后SQL Server Agent由于"The EventLog service has not been started" 启动失败
案例环境: 操作系统 : Microsoft Windows Server 2003 Standard Edtion SP2 数据库版本 : SQL Server 2005 Standard Ed ...
- 添加无线服务wzcsvc服务,Eventlog服务
<添加eventlog服务.reg> Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentCont ...
- 写window应用程序日志System.Diagnostics.EventLog.WriteEntry
System.Diagnostics.EventLog.WriteEntry( MySource , Writing to event log. ); 可以写window应用程序日志 查看的地方:右击 ...
随机推荐
- Tarjan 算法总结
一些概念 连通:无向图中的任意两点都可以互相到达. 强连通:有向图中的任意两点都可以互相到达. 连通分量:无向图的极大连通子图. 强连通分量:有向图的极大强连通子图. DFS 生成树:对一张图(有向无 ...
- JavaSE 学习笔记05丨泛型、集合
Chapter. 10 泛型 10.1 泛型程序设计 泛型,指可以在类或方法中预支地使用未知的类型.泛型程序设计(Generic programming),意味着编写的代码可被很多不同类型的对象所重用 ...
- Codeforces Round #661 (Div. 3) D、E1 题解
D. Binary String To Subsequences #贪心 #构造 题目链接 题意 给定一个\(01\)串\(s\),完全分割成若干子序列(注意,不要混淆子串与子序列的概念),其中的子序 ...
- 惠州发布5G任务计划表,将出台智慧灯杆建设计划与技术规范
广东省惠州市于近日发布<惠州市贯彻落实广东省加快5G产业发展行动计划(2019-2022年)工作任务计划表>(以下简称:<5G任务计划表>). <5G任务计划表>明 ...
- js中定时器调用函数时为什么会有引号
之前在学习的时候并没有发现的细节,关于js中,定时器的问题 这里我们写两个延时器 setTimeout(func, 0); setTimeout("func()", 0);定时器中 ...
- VC与VB
VB调用VC dll的返回方式 第一种类型:数值传递注意:在VB中,默认变量传递方式为ByRef为地址,而传递值就是用ByVal,还要注意在C++中,int类型的变量是32位的,在VB中要用long型 ...
- java12(eclipse断点调试)
选择结构switch 1.格式: switch(整型数据){ case 值A:System.out.println("");break; case 值B:System.out.pr ...
- Beta冲刺随笔——测试
这个作业属于哪个课程 软件工程 (福州大学至诚学院 - 计算机工程系) 这个作业要求在哪里 团队作业第五次--Alpha冲刺 这个作业的目标 团队进行Alpha冲刺 作业正文 正文 其他参考文献 无 ...
- 排序-InsertionSort 插入排序
插入排序 の implementation 插入排序就像打赌的时候,比如双扣.抽牌的时候,一次拿一张牌,这张牌和之前的牌一张张比较.选择把这张牌插入什么位置,排好顺序的位置后打牌更顺.要不然得一个一个 ...
- java并发编程实战《二十一》无锁工具类
不安全的累加代码,如下 1 public class Test { 2 long count = 0; 3 void add10K() { 4 int idx = 0; 5 while(idx++ & ...