c# – 事件日志写入错误
发布时间:2020-12-15 06:53:55 所属栏目:百科 来源:网络整理
导读:很简单,我想写一些事情日志. protected override void OnStop() { // TODO: Add code here to perform any tear-down necessary to stop your service. if (!System.Diagnostics.EventLog.SourceExists("IvrService")) { System.Diagnostics.EventLog.Create
很简单,我想写一些事情日志.
protected override void OnStop() { // TODO: Add code here to perform any tear-down necessary to stop your service. if (!System.Diagnostics.EventLog.SourceExists("IvrService")) { System.Diagnostics.EventLog.CreateEventSource( "IvrService","IvrServiceLog"); } EventLog eventLog1 = new System.Diagnostics.EventLog(); eventLog1.Source = "IvrService"; eventLog1.Log = "IvrServiceLog"; try { eventLog1.WriteEntry("Successfully "+State.Stopped.ToString()); IvrApplication.StopImmediate(); } catch (Exception ex) { // eventLog1.WriteEntry(ex.Message); } } 例外是: Failed to stop service. System.ArgumentException: The source 'IvrService' is not registered in log 'IvrServiceLog'. (It is registered in log 'Application'.) " The Source and Log properties must be matched,or you may set Log to the empty string,and it will automatically be matched to the Source property. at System.Diagnostics.EventLogInternal.VerifyAndCreateSource(String sourceName,String currentMachineName) at System.Diagnostics.EventLogInternal.WriteEntry(String message,EventLogEntryType type,Int32 eventID,Int16 category,Byte[] rawData) at System.Diagnostics.EventLog.WriteEntry(String message) 解决方法
错误信息告诉你什么是错误的.您已将事件源IvrService注册到应用程序日志,而不是IvrServiceLog. System.Diagnostics.EventLog.SourceExists验证源是否存在,但不是用于特定日志.
我的猜测是,您最初在应用程序日志中注册了该文件,然后将其更改为写入IvrServiceLog. 要清理您的开发机器,您可以简单地运行以下内容,然后您的代码应该继续工作. System.Diagnostics.EventLog.DeleteEventSource("IvrService"); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- reactjs – React Router不呈现Component
- 避免浮动广告、在线客服等弹出层被页面Flash内容遮住?
- c# – Check包含null属性的int数组
- ruby-on-rails – 在Rails应用程序中查找未使用的图像?
- postgresql – 每天选择特定时间范围的时间戳数据
- Flex / Flash Builder:引用另一个项目的正确方法?
- PostgreSQL 使用anto_explain自动记录超时SQL的执行计划
- Flex tree 双击展开收起节点,更改图标设置
- c# – 检查表是否包含重叠的时间跨度
- 仿百度文库方案[openoffice.org 3+swftools+flexpaper](三)