1. 专门创建Source的Log  

创建了Source,log显示在  Event viewer/Applications and Services logs/ 自定义Source 中,待遇比较高,专门显示的。

C# :试玩EventLog
创建Source需要管理员身份,否则Crash。

如果已经打开了 Computer Management,请关闭然后再打开,才能看到刚才创建的Source。
代码如下

  // Create the source, if it does not already exist.
                if (!EventLog.SourceExists(logSource))
                {
                    EventLog.CreateEventSource(logSource, logName);
                }

                EventLog.WriteEntry(tbSourceName.Text, tbMessage.Text, type, getValue(tbEventID.Text), getShortValue(tbCategory.Text));

Source 创建后,写入日志就不需要管理员身份了。

实际使用场合,安装软件的时候,创建一下Source。


2. 不创建Source,代码就一句

 EventLog.WriteEntry(tbSourceName.Text, tbMessage.Text, type, getValue(tbEventID.Text), getShortValue(tbCategory.Text));

这个每次运行都需要管理员身份,比较扯淡。

日志显示在 Event Viewers/Windows Logs/Application 中.

C# :试玩EventLog

 

3. 每一条log,都有 General和Details 两个信息,算是详细,但貌似又没啥用。

 

总之,不太爽。

写的也乱,见谅!

 Demo

 

相关文章:

  • 2022-12-23
  • 2022-03-02
  • 2022-01-31
  • 2021-06-07
  • 2022-02-04
  • 2022-12-23
  • 2022-12-23
  • 2022-02-22
猜你喜欢
  • 2022-12-23
  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
  • 2021-10-24
相关资源
相似解决方案