Boo
Boo

Reputation: 1644

Manual Elmah logging

how I can use Elmah logger only when I want? I have ErrorsController and I need log it only when excpetion is unknown:

Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(string.Format("{0}, {1}", controller, action), exception));

I didn't implement ElmahAttributes, Elmah added only in web.config. How I can do that? I have idea to use some errorFilter that will filter all incoming errors, but it's not very good, I think.

UPD

I have add filter that ignores all errors:

<errorFilter>
  <ignoreAll>
      <regex binding="Context.Request.Url" pattern="." />
  </ignoreAll>
</errorFilter>

but it ignores absolutely everything, even that I call to log manually.

Upvotes: 2

Views: 2161

Answers (2)

Boo
Boo

Reputation: 1644

I understand why filter ignores error - because when using Elmah.ErrorSignal.FromCurrentContext().Raise() we are "emulate" process of getting error and this errors fall under the filter. Instead of this method we should use Elmah logger method to add error to log:

Elmah.ErrorLog.GetDefault(System.Web.HttpContext.Current).Log()

This method will add error to log and filter below will ignore all others:

<errorFilter>
  <test>
    <regex binding="Context.Request.Url" pattern="." />
  </test>
</errorFilter>

After all this I have one question - name tag inside <errorFilter> can only be test?

Upvotes: 3

Eranga
Eranga

Reputation: 32437

You can configure it in Web.Config file. Check this wiki

Upvotes: 0

Related Questions