LogToOperations does not log to Event Log

Nov 29, 2010 at 2:50 PM

Hi,

Im having issues logging to the event log. I've followed the guidance: created my own area and categories, added these to the DiagnosticsAreaCollection retreived with the IConfigManager, run the EnsureConfiguredAreasRegistered method...

I can see my area and categories under Diagnostic Logging settings in CA and my messages is logged to the ULS log as expected. Should I see the area (event source) in the registry somewhere? (I dont).

Is there something I might have forgotten to do? Any feedback or suggestion is appriciated!

 

Regards,
Martin

Dec 1, 2010 at 10:05 AM

Hi Martin,

I am not sure what it happens in your program. As we know, the area is used as the event source name in the Windows event logs. Event sources for Windows event logs must be added to the registry on the local machine. To enable SharePoint to use a custom diagnostic area as a Windows event source, you must register the event sources on each Web front end server.If you do not register the logger with SharePoint prior to using it from a content web then a security exception will be thrown.

Hope to have helps for your question.

 

Regards,

Richie

Dec 1, 2010 at 10:19 AM

Hi Richie and thanks for your reply.

I thought that the event source should be registered in the registry by running the DiagnosticsAreaEventSource.EnsureConfiguredAreasRegistered() method. Must I add the appropriate registry key manually?

I dont get a security exception when trying to log. In fact, I dont get any exception at all...

 

Regards,
Martin

Dec 1, 2010 at 12:12 PM

That method should take care of it Martin, but as Richie mentioned, it must be ran on every WFE.  This can either be done manually or through a custom timer job.

One other thing to check - what are the filter levels set to in central admin?  Could it be that the level for the events is being filtered out because the filter level is set to a value of error or critical?

Chris

Dec 1, 2010 at 12:49 PM

I've run the method on every WFE (I only have one server in my dev env) inside a FeatureInstalled method (so I should have the appropriate rights, right?). The filter levels are set to information and im trying to log an error.

Martin

Dec 1, 2010 at 1:10 PM

FeatureInstalled will not run on every WFE (that is a frequent misconception - we had to clear that one up ourselves).  If you only have one server though that should work fine.

One other thing to check - Where in the event log are you looking?  They can show up either in the SharePoint section under application and services log, or in the default application log.

If you are seeing the entry go into the ULS, that means that SharePoint has the event (we rely upon SharePoint to both log to the ULS, and log to the event log, when logging an event entry). 

Dec 2, 2010 at 6:09 AM

Thank you Chris! You made my day! :)

I was only looking in the Application log, but the events were written to the SharePoint Event log. So everything seems to work fine.

One last question: Is it possible to log to the Application logs instead of the SharePoint section under application and services?

 

Best regards,
Martin