【发布时间】:2012-04-21 22:24:06
【问题描述】:
我正在尝试在我的控制台应用程序中使用 ELMAH。我只是想学习绳索,所以请原谅我的 .net 经验不足。我只想创建一个非常简单的控制台应用程序并使用 ELMAH 来登录 XML 文件。我已经从 NuGet 下载并安装了"Elmah on XML Log"。所以,我认为它在我的参考文件夹中是活跃的。我已按照this link 中的说明进行操作:
当然,我已经对其稍作修改以使用 XML。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah"/>
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah"/>
<section name="errorTweet" requirePermission="false" type="Elmah.ErrorTweetSectionHandler, Elmah"/>
</sectionGroup>
</configSections>
<elmah>
<security allowRemoteAccess="yes" />
<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="C:\temp\elmah_logs\" />
</elmah>
<system.web>
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
</httpModules>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
</system.web>
<location path="elmah.axd">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
但在我的主程序中,我无法访问参考并开始使用 ELMAH。这是我非常简单的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Elmah; // Complains that missing a directive or assembly
namespace Test_004
{
class Program
{
static void Main(string[] args)
{
int y = 4;
int z = 0;
try
{
var x = y / z;
}
catch (Exception ex) ErrorSignal.FromCurrentContext().Raise(ex); // because of above, this fails
}
}
}
我在这里缺少什么?在此先感谢 .Net n00bie。
也许,以下错误可能会有所启发:
错误 1 找不到类型或命名空间名称“Elmah”(您是否缺少 using 指令或程序集引用?)
警告 2 引用的程序集“Elmah”无法解析,因为它依赖于“System.Web,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”,它不在当前目标框架中。 NETFramework,版本=v4.0,配置文件=客户端”。请删除对不在目标框架中的程序集的引用,或考虑重新定位您的项目。测试_004
警告 3 引用的程序集“Elmah”无法解析,因为它依赖于“System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”,这不在当前目标框架中“.NETFramework,版本=v4.0,配置文件=客户端”。请删除对不在目标框架中的程序集的引用,或考虑重新定位您的项目。测试_004
【问题讨论】:
-
你的引用文件夹中有 Elmah 吗?
-
是的,我愿意。我从 Nuget 安装并激活了包。