1

I'm trying to use ELMAH in my console app. I'm just trying to learn the ropes so pardon my .net inexperience. I just want to create a very simple console app & use ELMAH for logging in XML files. I have downloaded & installed "Elmah on XML Log" from NuGet. So, it is active in my references folder, I think. I've followed the instructions in this link:

Of course I've modified it slightly to use 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>

But in my main program, I can't access the reference and start using ELMAH. Here's my very simple code:

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
    }
}
}

What am I missing here? Thanks in advance from .Net n00bie.

Maybe, it the following errors might shed some light:

Error 1 The type or namespace name 'Elmah' could not be found (are you missing a using directive or an assembly reference?)

Warning 2 The referenced assembly "Elmah" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project. Test_004

Warning 3 The referenced assembly "Elmah" could not be resolved because it has a dependency on "System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project. Test_004

inquisitive_one
  • 1,363
  • 6
  • 29
  • 55

2 Answers2

3

My guess would be that you need to change your console applicaiton to use the full framework not the client framework. You can do that from the property pages of the Console application (I think it is the build tab, but I cant check as I do not have VS installed here).

gbanfill
  • 2,196
  • 13
  • 21
-1

ELMAH is designed for ASP.NET applications, not console apps.

However, there is a similar question here with some suggestions for how to use it for console apps.

Community
  • 1
  • 1
shamp00
  • 10,504
  • 3
  • 31
  • 76
  • I saw that post, but any idea why my intelisense doesn't work? I'm using all the necessary references but i'm still getting errors. – inquisitive_one Apr 09 '12 at 19:46