Developer forum

Forum » Development » Problem with logging session

Problem with logging session

Anders Ebdrup
Reply

Hi,

 

This is not a question, but a general problem when using the api...

 

I have a problem with the error logging method: "Dynamicweb.Log", where this line assumes that a session is available:

For Each key As String In HttpContext.Current.Session.Keys
  sessionKeys.Add(key)
Next

But a session is not always available for callbacks from payment gateways, web services and wcf services, and this causes another exception to be throw by the error logger :-)

Because of that I have a lot of log files which contains:

 

Exception while logging 'Session':    System.NullReferenceException
Exception message:    Object reference not set to an instance of an object.
Stack Trace:
   at Dynamicweb.LogToFile.Log(String message, Exception logException, String folder, LogType newLogFile, Boolean useExtendedPropertyLogging, LogElements logElements)

If anybody have the same problem then please make a vote for this to be fixed :-)


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Anders

 

You can use the overload with the parameter "logElements" - that is an enum where you can specify what you want logged:

 

See i.e. this:

http://developer.dynamicweb-cms.com/api8/#Dynamicweb~Dynamicweb.LogToFile~Log%28String,String,LogType,Boolean,LogElements%29.html

 

And the available options:

http://developer.dynamicweb-cms.com/api8/#Dynamicweb~Dynamicweb.LogToFile+LogElements.html

 

The for the logElements parameter, you can specify a list of what you want:

VB

LogElements.StackTrace Or LogElements.URL Or LogElements.Items

Or C#

 

LogElements.StackTrace | LogElements.SessionVariables | LogElements.URL | LogElements.Items

 

 

BR Nicolai

 
Anders Ebdrup
Reply

Thank you for very quick reply - I know the option, but in general I always want to log as many informations as possible - even the session if available.

 

Will you then recommend me to override the DW implementation of the LogProvider, which will check if the session exists and then call LogToFile.Log for each of the other options in the LogElements enum and have it separated into different log files?? That doesn't sounds reasonable for me :-)

 

//Anders

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

For now that would be you approach.

 

I have of course made changes to the log method so it checks first to see if the HttpSessionState etc are null. The you do not get null reference exceptions any more.

 

BR Nicolai

Votes for this answer: 1
 
Anders Ebdrup
Reply

You're the best, thank you, Nicolai! :-)

 
Nicolai Høeg Pedersen
Reply

TFS #11671

 

You must be logged in to post in the forum