Anyway I can get Elmah working while using Net.tcp???

182 views
Skip to first unread message

_Mr_E

unread,
Mar 15, 2011, 10:11:49 AM3/15/11
to ELMAH
I'm working with a large app that uses net.tcp bindings and after
three days of wondering why the hell my HttpContext.Current was null
when all the compatibility was set up I finally learned it was my
net.tcp binding. Yet a desperately need to get Elmah running:( What
can be done about this?

James_2JS

unread,
Mar 15, 2011, 11:02:06 AM3/15/11
to ELMAH
Hi there,

I'm not really into WCF, but I believe there are a few resources out
there that can help...
Unfortunately I don't have an environment/sample source code to test
this out, so you'll have to do much of the leg work!

Firstly read this: http://dotnetslackers.com/articles/aspnet/Getting-ELMAH-to-work-with-WCF-services.aspx
From what I've read of the code, it seems to do much of what you
require... except the final bit of working the NetTcpBinding...
But... I think the code in listing 5..
http://dotnetslackers.com/articles/aspnet/Getting-ELMAH-to-work-with-WCF-services.aspx#s7-coding
...can be improved upon.
Instead of the

if (HttpContext.Current == null) //In case we run outside of IIS
return;
Elmah.ErrorSignal.FromCurrentContext().Raise(error);

You could try this instead:

if (HttpContext.Current == null) //In case we run outside of IIS
// see http://groups.google.com/group/elmah/browse_thread/thread/9ea4b51420fd5dfa
ErrorLog.GetDefault(null).Log(new Error(e));
else
Elmah.ErrorSignal.FromCurrentContext().Raise(error);

NB this won't filter the error, or email it... but it might be a
start!
Let us know how you get on!!

Thanks,

James

_Mr_E

unread,
Mar 15, 2011, 11:38:39 AM3/15/11
to ELMAH
Hmm this definately got me closer. It is creating a log in the
database but the "Application" field is empty. When I try to view it
on the website it doesn't show up, I'm guessing for this reason. Is
that what you meant by "filters" won't work? Any suggestions... I'm
quite the Elmah noob.

On Mar 15, 11:02 am, James_2JS <jamesdrisc...@btinternet.com> wrote:
> Hi there,
>
> I'm not really into WCF, but I believe there are a few resources out
> there that can help...
> Unfortunately I don't have an environment/sample source code to test
> this out, so you'll have to do much of the leg work!
>
> Firstly read this:http://dotnetslackers.com/articles/aspnet/Getting-ELMAH-to-work-with-...
> From what I've read of the code, it seems to do much of what you
> require... except the final bit of working the NetTcpBinding...
> But... I think the code in listing 5..http://dotnetslackers.com/articles/aspnet/Getting-ELMAH-to-work-with-...
> ...can be improved upon.
> Instead of the
>
>   if (HttpContext.Current == null) //In case we run outside of IIS
>     return;
>   Elmah.ErrorSignal.FromCurrentContext().Raise(error);
>
> You could try this instead:
>
>   if (HttpContext.Current == null) //In case we run outside of IIS
>     // seehttp://groups.google.com/group/elmah/browse_thread/thread/9ea4b51420f...

_Mr_E

unread,
Mar 15, 2011, 11:55:15 AM3/15/11
to ELMAH
Before when I was trying to get this working I was getting "Activation
Errors" and Elmah was working properly even with the default code:
if (HttpContext.Current == null) //In case we run outside of IIS
return;
This is what really threw me for a loop when HttpContext.Current was
always null thereafter, yet I managed to somehow get three logs into
the database. Anyway those logs were created with the field
"Application" as "/LM/W3SVC/1/ROOT/SSCL.SQS.MT.IISMiddleTierHost".
Those are still showing up on the website but the new ones all have
"Application" blank and don't show up, that is why I believe it is the
cause.

Tony Bunce

unread,
Mar 15, 2011, 12:09:36 PM3/15/11
to el...@googlegroups.com
Try setting the AppliationName in your web.config file:
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="xxxx" applicationName="YourAppliationName" />

The Error Logger doesn't have an HTTP Context so it can't auto-generate the application name like the web interface. If you specify an application name it should use the same application name using both GetDefault().Log and FromCurrentContext().Rase().

-Tony

--
You received this message because you are subscribed to the Google Groups "ELMAH" group.
To post to this group, send email to el...@googlegroups.com.
To unsubscribe from this group, send email to elmah+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/elmah?hl=en.


James_2JS

unread,
Mar 15, 2011, 12:08:46 PM3/15/11
to ELMAH
Excellent news!!

If you look down the previously linked post you will see this message:
http://groups.google.com/group/elmah/msg/01252441bfbdbeb4

The key bit to look at is this:

I changed the web.config to
<errorLog type="Elmah.SqlErrorLog, Elmah"
connectionString="Server=.;Database=elmahdb;Trusted_Connection=True;"
applicationName="MyApp"/>

Hopefully that's the last piece of the puzzle for you!!

As for filtering... basically this is an ELMAH mechanism that allows
you to filter out certain exceptions rather than logging them - e.g.
HTTP 404 errors - I know this doesn't apply to you :O)
See http://code.google.com/p/elmah/wiki/ErrorFiltering for more info.

Once you're done, would you be kind enough to share some or all of
your solution so that others can benefit too - (even if it is simply
confirming that you followed the linked articles step by step!)??
> > > can be done about this?- Hide quoted text -
>
> - Show quoted text -

_Mr_E

unread,
Mar 15, 2011, 1:40:13 PM3/15/11
to ELMAH
Well that did work but now I'm starting to think there may actually be
a bigger piece of the puzzle missing:(
When I click on my initial errors I seem to get way more information
then I am getting now. Does this have to do with the particular error
I threw or is all this extra information based on the HttpContext? See
these screenshots:

Before: http://i.imgur.com/hzfCs.jpg
After: http://i.imgur.com/MIqq5.jpg

On Mar 15, 12:08 pm, James_2JS <jamesdrisc...@btinternet.com> wrote:
> Excellent news!!
>
> If you look down the previously linked post you will see this message:http://groups.google.com/group/elmah/msg/01252441bfbdbeb4
>
> The key bit to look at is this:
>
> I changed the web.config to
>    <errorLog type="Elmah.SqlErrorLog, Elmah"
> connectionString="Server=.;Database=elmahdb;Trusted_Connection=True;"
> applicationName="MyApp"/>
>
> Hopefully that's the last piece of the puzzle for you!!
>
> As for filtering... basically this is an ELMAH mechanism that allows
> you to filter out certain exceptions rather than logging them - e.g.
> HTTP 404 errors - I know this doesn't apply to you :O)
> Seehttp://code.google.com/p/elmah/wiki/ErrorFilteringfor more info.

_Mr_E

unread,
Mar 15, 2011, 1:43:54 PM3/15/11
to ELMAH
Mind you this is not really a show stopper if so. Thanks for your help
up to this point.
And yes, I basically followed all these instructions to a tea. The
initial page at: http://dotnetslackers.com/articles/aspnet/Getting-ELMAH-to-work-with-WCF-services.aspx
was a huge help in getting Elmah set up and understanding it. I had
previously only played with the NuGet package. Mind you I skipped
bothering to set up the aspNetCompatibility tags in the web.config and
on the service class. I then simply replaced the line relying on the
HttpContext as you stated above and the errors started logging.

On Mar 15, 12:08 pm, James_2JS <jamesdrisc...@btinternet.com> wrote:
> Excellent news!!
>
> If you look down the previously linked post you will see this message:http://groups.google.com/group/elmah/msg/01252441bfbdbeb4
>
> The key bit to look at is this:
>
> I changed the web.config to
>    <errorLog type="Elmah.SqlErrorLog, Elmah"
> connectionString="Server=.;Database=elmahdb;Trusted_Connection=True;"
> applicationName="MyApp"/>
>
> Hopefully that's the last piece of the puzzle for you!!
>
> As for filtering... basically this is an ELMAH mechanism that allows
> you to filter out certain exceptions rather than logging them - e.g.
> HTTP 404 errors - I know this doesn't apply to you :O)
> Seehttp://code.google.com/p/elmah/wiki/ErrorFilteringfor more info.

Atif Aziz

unread,
Mar 15, 2011, 4:44:04 PM3/15/11
to el...@googlegroups.com
 is all this extra information based on the HttpContext?

Yes, all that extra information is generated from HttpContext whenever it's given. Your before and after screenshots don't appear to refer to the same scenario. In the before case, the request is reaching WCF over the ASP.NET pipeline (based on the stack trace) and therefore an HTTP context appears to be loaded. The second error seems to occur during an RPC invocation and is either not tunneling via HTTP or it's not integrated into the ASP.NET pipeline. I believe that in this second case, the following line is how logging is taking place:

ErrorLog.GetDefault(null).Log(new Error(e));

Because HttpContext.Current is null, all the extra info is either unavailable or irrelevant.

- Atif

Reply all
Reply to author
Forward
0 new messages