ELMAH not logging in ASP.NET MVC 2
I cannot figure out what I'm doing wrong here, trying to use ELMAH in my MVC 2 application and it doesnt log anything, ever.
Here's what I have in my web.config (relevant parts)
<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" />
</sectionGroup>
<elmah>
<security allowRemoteAccess="0" />
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="ELMAH.SqlServer" />
<!--
<errorMail from="youremail@example.com" to="youremail@example.com" cc="" subject="Elmah Error" async="true" smtpPort="25" smtpServer="[EmailServerName]" userName="" password="" />
<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data" />
-->
</elmah>
<connectionStrings>
...
<add
name="ELMAH.SqlServer"
connectionString="data source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ELMAH_Logging.mdf;Integrated Security=SSPI;Connect Timeout=30;User Instance=True;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.Web>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
...
</httpHandlers>
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
...
</httpModules>
</system.Web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
</modules>
<handlers>
<add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorL开发者_Python百科ogPageFactory, Elmah"/>
...
</handlers>
</system.webServer>
Then using the code from DotNetDarren.com but no matter what I do no exceptions are ever logged?
Elmah fails silently if it cannot log the errors...Recheck all ur connection strings used by elmah, you ,might see issues there.
Here's the table script used to make the DB table
CREATE TABLE [dbo].[ELMAH_Error](
[ErrorId] [uniqueidentifier] NOT NULL,
[Application] [nvarchar](60) NOT NULL,
[Host] [nvarchar](50) NOT NULL,
[Type] [nvarchar](100) NOT NULL,
[Source] [nvarchar](60) NOT NULL,
[Message] [nvarchar](500) NOT NULL,
[User] [nvarchar](50) NOT NULL,
[StatusCode] [int] NOT NULL,
[TimeUtc] [datetime] NOT NULL,
[Sequence] [int] IDENTITY(1,1) NOT NULL,
[AllXml] [varchar](max) NOT NULL,
CONSTRAINT [PK_ELMAH_Error] PRIMARY KEY NONCLUSTERED
(
[ErrorId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[ELMAH_Error] ADD CONSTRAINT [DF_ELMAH_Error_ErrorId] DEFAULT (newid()) FOR [ErrorId]
I'll have to echo Paul's preCondition but I also have preCondition="managedHandler"
under the modules section for every entry.
I also use allowRemoteAccess="1"
under elmah's security group but I locked down the path so that only admin level authenticated users could access the page via the controller call.
I noticed the XML error log entry commented out. Does it work at all via XML mode versus SQL? I know when I first started out I had to work in XML mode until I worked through connection string and database schema issues I was having.
You could also be running into full/medium trust issues depending on deployment but I think you get exceptions from elmah in those situations. Have you tried looking at the eventlog on the machine? That has also helped me with getting through the growing pains I had setting it up.
Lastly, I just noticed this in their Jan 14th changelog: http://code.google.com/p/elmah/source/detail?r=782 pointing to ELMAH - Filtering 404 Errors which merely says that the ErrorFilter module needs to be registered last for filtering to work as expected. You didn't paste filter config params so I doubt it applies but the order things are registered does matter apparently so maybe there is some relation.
I'm not sure if this will help you, but I've just run into the same problem with my 1st attempt to incorporate ELMAH into my site. Firstly I couldn't even see the error screen, secondly once I'd sorted that no errors were being reported. Both of these were caused by missing sections from system.WebServer. I'm using a MVC3.0 site (recently converted from 2.0). The only difference I can really see between my config and yours is that you don't have preCondition="integratedMode" in your handlers section of system.WebServer (see below). Maybe that is causing you the problems?
<handlers>
<add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
</handlers>
EDIT
Sorry that my original idea didn't help - just a couple more thoughts:
- Which version of ELMAH did you download (x86 or x64?) and which version of CPU are you building for? Have you tried setting your build CPU for the same version you downloaded.
- Do you have any "OnError" handling inside your global.asax, if so what happens if you remove that?
- Finally, have you tried building an empty MVC project with nothing other than ELMAH included just to make sure you can get that to log correctly.
精彩评论