• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
张继东
看铁蹄铮铮,踏遍万里河山。磨不破,打不烂。
   首页    新随笔    联系   管理    订阅  订阅

PetShop中报错的处理(EventLog.SourceExists的使用)问题

用PetShop改了个网站,不过程序一出现错误的时候就保“注册表无法访问”的错,
------------------------------------------------------------------------
{
    EventLog m_enentLog=null;
行 14:    if(!(EventLog.SourceExists(ERROR_LOG_SOURCE)))
行 15:    {
行 16:     EventLog.CreateEventSource(ERROR_LOG_SOURCE, "Application");
------------------------------------------------------------------------
原来PetShop中的错误是要写到操作系统日志中的,在Erro.cs中:
public class Error
 
{ //例如我的应用程序的名称是:comeday
  const string ERROR_LOG_SOURCE="comeday";
  
public static void  Log(string message)
  
{
   EventLog m_enentLog
=null;
   
if(!(EventLog.SourceExists(ERROR_LOG_SOURCE)))
   
{
    EventLog.CreateEventSource(ERROR_LOG_SOURCE, 
"Application");
   }

   
if(m_enentLog ==null)
   
{
    m_enentLog
=new EventLog("Application");
    m_enentLog.Source
=ERROR_LOG_SOURCE;
   }

   m_enentLog.WriteEntry(message,System.Diagnostics.EventLogEntryType.Error);
  }

 }

解决方法:
在注册表
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application
加入:项“comeday”(你的应用程序名称,我的是comeday)就OK了。
posted @ 2005-07-18 16:32  简单生活  阅读(749)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3