Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Using ELMAH without HttpContext
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Nick  
View profile  
 More options Jan 11 2010, 7:37 pm
From: Nick <nbera...@gmail.com>
Date: Mon, 11 Jan 2010 16:37:03 -0800 (PST)
Local: Mon, Jan 11 2010 7:37 pm
Subject: Using ELMAH without HttpContext
Is it possible to use ELMAH to log errors in say a console app?  I
haven't had too much luck getting this to work.  Anybody have any
pointers.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Atif Aziz  
View profile  
 More options Jan 12 2010, 2:23 am
From: Atif Aziz <aziza...@gmail.com>
Date: Tue, 12 Jan 2010 08:23:51 +0100
Local: Tues, Jan 12 2010 2:23 am
Subject: Re: [ELMAH] Using ELMAH without HttpContext

Hi Nick,

Technically, it is possible to get ELMAH to log exception in a console
application but obviously the HTTP modules and handlers won't do anything
automagically. There is nothing preventing you from creating an instance of,
for example, SqlErrorLog and calling its Log method. If you want to pick up
the log currently configured, you can use ErrorLog.GetDefault(null) where
null is allowed for HttpContext. However,I introduced a regression bug
recently when working on issue
149<http://code.google.com/p/elmah/issues/detail?id=149> that
prevented from null being passed to GetDefault but I've
fixed<http://code.google.com/p/elmah/source/detail?r=701>that now.
With that said, here's an example in showing ELMAH being used to
log an error using IronPython's interactive interpreter on the console:

IronPython 2.6 (2.6.10920.0) on .NET 2.0.50727.4200
Type "help", "copyright", "credits" or "license" for more information.

>>> import clr
>>> clr.AddReference('Elmah')
>>> from Elmah import Error, ErrorLog
>>> from System import ApplicationException
>>> from System.Collections import ArrayList
>>> log = ErrorLog.GetDefault(None)
>>> print log

<Elmah.MemoryErrorLog object at 0x000000000000002B [Elmah.MemoryErrorLog]>
>>> log.Log(Error(ApplicationException()))

'79e8f86c-e82f-4051-949c-14b8a8bdcf03'
>>> errors = ArrayList()
>>> total = log.GetErrors(0, 10, errors)
>>> print 'Total =', total, '; Count =', errors.Count

Total = 1 ; Count = 1
>>> error = errors[0]
>>> print error.Id, error.Error.Message

79e8f86c-e82f-4051-949c-14b8a8bdcf03 Error in the application.

- Atif


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nick Berardi  
View profile  
 More options Jan 12 2010, 8:41 am
From: Nick Berardi <nbera...@gmail.com>
Date: Tue, 12 Jan 2010 08:41:13 -0500
Local: Tues, Jan 12 2010 8:41 am
Subject: Re: [ELMAH] Using ELMAH without HttpContext

I still understand the need for IIS.  But I have some non-web, outside
processing tools, that need to be logged and it seemed easier to just put
all the logging in the same place.  So that was the reason for my question.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mhadamji  
View profile  
 More options Jan 26 2010, 7:00 am
From: mhadamji <mhada...@gmail.com>
Date: Tue, 26 Jan 2010 04:00:24 -0800 (PST)
Local: Tues, Jan 26 2010 7:00 am
Subject: Re: Using ELMAH without HttpContext
Hi Atif
Your suggested method of calling below works well using XML logger.
Elmah.ErrorLog.GetDefault(null).Log(new Error(ex));
When I switch to SQL Logger it does not log any entry. Any Ideas?

On Jan 12, 7:23 am, Atif Aziz <aziza...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nick Berardi  
View profile  
 More options Jan 26 2010, 10:55 am
From: Nick Berardi <nbera...@gmail.com>
Date: Tue, 26 Jan 2010 10:55:02 -0500
Local: Tues, Jan 26 2010 10:55 am
Subject: Re: [ELMAH] Re: Using ELMAH without HttpContext

Same issue that I found.  XML seems to work fine, but SQL doesn't work for
me.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Atif Aziz  
View profile  
 More options Jan 26 2010, 2:28 pm
From: Atif Aziz <aziza...@gmail.com>
Date: Tue, 26 Jan 2010 20:28:11 +0100
Local: Tues, Jan 26 2010 2:28 pm
Subject: Re: [ELMAH] Re: Using ELMAH without HttpContext

Can you guys report this as an issue with details to reproduce and version
in question?
http://code.google.com/p/elmah/issues/entry

We have many SQL-based stores supported in ELMAH. I'm not sure if SQL means
MS SQL Server or just all SQL-based loggers.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Atif Aziz  
View profile  
 More options Jan 26 2010, 2:30 pm
From: Atif Aziz <aziza...@gmail.com>
Date: Tue, 26 Jan 2010 20:30:17 +0100
Local: Tues, Jan 26 2010 2:30 pm
Subject: Re: [ELMAH] Re: Using ELMAH without HttpContext

I just run a test with SqlErrorLog backed by a database in SQL Server
Express from the console and it seems to be working fine...

IronPython 2.6 (2.6.10920.0) on .NET 2.0.50727.4200
Type "help", "copyright", "credits" or "license" for more information.

>>> import clr
>>> clr.AddReference('Elmah')
>>> from System import ApplicationException
>>> from System.Collections import ArrayList
>>> from Elmah import Error, ErrorLog, SqlErrorLog
>>> log =

SqlErrorLog(r'Server=.\SQLEXPRESS;Database=ELMAH;Trusted_Connection=True')
>>> log.ApplicationName = 'TestApp'
>>> log.Log(Error(ApplicationException()))

'5c92599d-46e3-4fdf-8a29-4411c214caaa'
>>> errors = ArrayList()
>>> total = log.GetErrors(0, 10, errors)
>>> print 'Total =', total, '; Count =', errors.Count

Total = 1 ; Count = 1
>>> error = errors[0]
>>> print error.Id, error.Error.Message

5C92599D-46E3-4FDF-8A29-4411C214CAAA Error in the application.

- Atif


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mhadamji  
View profile  
 More options Jan 26 2010, 8:42 pm
From: mhadamji <mhada...@gmail.com>
Date: Tue, 26 Jan 2010 17:42:04 -0800 (PST)
Local: Tues, Jan 26 2010 8:42 pm
Subject: Re: Using ELMAH without HttpContext
Thanks Atif
I am using MS-SQL 2005 developer edition with following connection
string.
   <errorLog type="Elmah.SqlErrorLog, Elmah"
connectionString="Server=.;Database=elmahdb;Trusted_Connection=True;"/


The following error gets logged when called as below.
Elmah.ErrorLog.GetDefault(null).Log(new Error(ex));

However it does not get displayed in the elmah.axd file.

Looking at the source code in SqlErrorLog.cs line 86
string appName = Mask.NullString((string)config["applicationName"]);
The above connection string has not been passed with application name
and results in string.emtpy. The stored procedure fails when called
with application name as emtpty string.

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

Having set the application name in the config file, logs and displays
all the errors in the display logs correctly.

Setting the applicationName has resolved my problem.

Thanks

On Jan 26, 7:30 pm, Atif Aziz <aziza...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Atif Aziz  
View profile  
 More options Jan 28 2010, 3:31 pm
From: Atif Aziz <aziza...@gmail.com>
Date: Thu, 28 Jan 2010 21:31:32 +0100
Local: Thurs, Jan 28 2010 3:31 pm
Subject: Re: [ELMAH] Re: Using ELMAH without HttpContext

Glad to hear you could get it solved. Your solution is also consistent with
the test I did earlier where I specifically did set the application name. If
you don't set it then the problem is that ELMAH cannot infer it
automatically because there is no context available. See
ErrorLog.InferApplicationName for details:

http://tinyurl.com/errorlog-inferappname

ELMAH thereofre ends up using a blank for application name. The error is
probably getting logged but you can't see it through the views because they
filter the log based on an application name. Since the views are being
served in response to a web request, the context is available for inference
and a different application name is being used.

Hope this clears up things.

- Atif


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jed  
View profile  
 More options Feb 14 2010, 8:45 pm
From: Jed <JedSpr...@mkgcs.com>
Date: Sun, 14 Feb 2010 17:45:19 -0800 (PST)
Local: Sun, Feb 14 2010 8:45 pm
Subject: Re: Using ELMAH without HttpContext
An option for people without a context in Global.asax Session_End /
Application_End:

 public class Global : System.Web.HttpApplication
 {
  protected void Session_End(object sender, EventArgs e)
  {
    Elmah.ErrorSignal.Get(this).Raise(...);
  }
 }

Original discussion of this as a documentation issue:

 http://code.google.com/p/elmah/issues/detail?id=30

~Jed


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »