首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > .NET > VB.NET > .NET 中对日志操作时的一个问题
【标  题】:.NET 中对日志操作时的一个问题
【关键字】:.NET
【来  源】:http://blog.joycode.com/moslem/archive/2005/04/02/46843.aspx

.NET 中对日志操作时的一个问题

近几天用 C# 在对日志进行操作的时候,发现经常无法正常写入正确的日志条目,经过测试,发现这可能是 .NET 的一个 Bug ,重现/测试程序如下:

static void Main(string[] args) { string sSource = "DotNetMySource"; string sLog = "DotNetMyLog"; //新建日志文件及源并写入一条日志 if(!EventLog.SourceExists(sSource)) { EventLog.CreateEventSource(sSource,sLog); Console.WriteLine("Source Created"); } EventLog log = new EventLog(); log.Source = sSource; log.WriteEntry("Hello China"); Console.WriteLine("Log Entry Writed"); Console.ReadLine(); //删除刚才的建立日志文件及源 if(EventLog.SourceExists(sSource)) { EventLog.DeleteEventSource(sSource); Console.WriteLine("Source Deleted"); } else { Console.WriteLine("Source Not Found"); } if(EventLog.Exists(sLog)) { EventLog.Delete(sLog); Console.WriteLine("Log Deleted"); } else { Console.WriteLine("Log Not Found"); } Console.ReadLine(); //重新建立同样的日志文件及源 if(!EventLog.SourceExists(sSource)) { EventLog.CreateEventSource(sSource,sLog); Console.WriteLine("Source Created"); } log = new EventLog(); log.Source = sSource; log.WriteEntry("Hello China Again"); Console.WriteLine("Log Entry Writed"); Console.ReadLine(); }

在程序运行的三个步骤中,你需要打开/关闭“日志查看器”以确定每次程序执行的结果(日志查看器中的刷新功能,不能刷新新建立的日志文件)。

在最后程序执行结束后,你会发现新写入的日志条目的“源”属性为空,而不是预计的 "DotNetMySource"。

甚至有时候会出现把日志写入到 Application 日志文件中的情况,且在日志查看器中会看到如下的消息(英文 OS):

The description for Event ID ( 0 ) in Source ( DotNetMySource ) cannot be
found. The local computer may not have the necessary registry information or
message DLL files to display messages from a remote computer. You may be
able to use the /AUXSOURCE= flag to retrieve this description; see Help and
Support for details. The following information is part of the event: Hello China Again

目前似乎没有别的解决办法,在 VS.NET 中直接删除日志文件,也会出现同样的问题,只有换用不同的 Source Name 和 Log Name 了,如果不删除,在写入新的 Log Entry 时好象没有这样的问题。

希望大家有时间测试一下,也希望 MS 的同志们确认是否是一个 Bug。

 

Happy Accident ?!:【上一篇】
SQL Server 2005 RTM 安装错误 :The SQL Server System Configuration Checker cannot be executed due to WMI configuration ..:【下一篇】
【相关文章】
  • ASP.NET中的OutOfMemoryException
  • ASP.NET 2.0 Provider Toolkit
  • 不使用IA,在.NET代码中调用Office
  • ASP.NET 2.0与SharePoint 2.0
  • Office with .Net (二) ――― 使用.Net访问Office编程接口
  • Office with .Net(二)之外传―――“彻底干净的”关闭Office程序
  • Office with .Net 系列之 ――― 在自己的程序中宿主Office
  • 新春送礼:Visual Studio.NET墙纸及桌面主题
  • 是.NET Bug不断吗?
  • ASP.NET 2.0 Tips(1):跨页提交
  • 【随机文章】
  • jython 2.2 beta1 发布
  • 【分享】最新破解软件下载
  • Session宝典应用深入探讨论(.net 中应用,如何联上SQLServer、临时表…)
  • 利用SharpZipLib实现压缩多个文件或整个目录
  • 听起来更完美:优化你的MP3文件
  • Oracle乱码的一种解决方法
  • [泡泡堂]泡泡堂标爆,引爆及攻略
  • 利用LLKM处理网络通信---对抗IDS、Firewall
  • 简单的将String类型的xml转换为对象的代码
  • 心情娃娃诞生记(无聊的娃娃)
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.