Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

This is similar to "http://sharepoint.stackexchange.com/questions/2057/how-to-write-to-uls-log-in-sharepoint-2010-from-a-net-app". But in my case, logs are NOT showing up in ULS when logging from a web app.

App Pool accounts ARE ALL in the "Performance Log Users" group. Permissions on the LOGS directory seem to be correct, based on looking at other machines where logging is working.

The line of code I'm running in Page_Load of a simple application page, for testing, is:

SPDiagnosticsService.Local.WriteTrace(1234, 
    new SPDiagnosticsCategory("My Errors", TraceSeverity.Monitorable, EventSeverity.Error),
    TraceSeverity.Monitorable, "Exception occured: {0}", new object[] { "NOT!" });

When I write the same line in a console app or linqpad, it logs just fine.

Any ideas of what else I can look at to figure this out?

share|improve this question
    
The web application you are referencing -is- a SharePoint site collection, right? Or are you trying to write to the uls from a standard asp.net web app?? –  SPArchaeologist Feb 8 '12 at 11:12
    
-- thanks to everyone who tried to help out here -- just to put this to rest, it turns out the problem was in a custom Autofac module (the SharePoint IoC container we are using) with a bad logging implementation which was locking up the SPDiagnosticsService. We fixed the implementation and everything is a go now ... –  James Feb 24 '12 at 17:39
add comment

2 Answers

Have you tried running your logging code using elevated privileges?

SPSecurity.RunWithElevatedPrivileges(delegate() {
   SPDiagnosticsService.Local.WriteTrace(1234, 
       new SPDiagnosticsCategory("My Errors", TraceSeverity.Monitorable, EventSeverity.Error),
       TraceSeverity.Monitorable, "Exception occured: {0}", new object[] { "NOT!" });
});
share|improve this answer
add comment

One of possible reasons is that your custom category (eg. 'My Errors') and/or area doesn't exist. AFAIK you should receive error about that in ULS.

To list all available categories you can use PS and Get-SPLogLevel

Also check SPDiagnosticsServiceBase.WriteTrace Method

You must use a category that is recognized by the service. For an example showing how to query a diagnostics services for areas and categories, see the Areas property.

Keep in mind that if you pass a value in the severity parameter that is less than the currently configured value for the category's TraceSeverity property, the trace is not written to the log.

share|improve this answer
    
Thanks for getting back on this. The code I pasted works in other environments, just not the one I'm debugging now. For example, to get back to your point, if I use an existing area and category, it still doesn't work from the web app (does work in the console and/or linqpad). For example: var category = SPDiagnosticsService.Local.Areas["SharePoint Foundation"].Categories["General"]; SPDiagnosticsService.Local.WriteTrace(1234, category, TraceSeverity.High, "Exception occured: {0}", new object[] { "NOT!" }); It most likely has to be an infrastructure thing. –  James Feb 7 '12 at 20:34
    
On thing (maybe not related¸but you never know): Instead of using Page_Load (default) try to use override OnLoad() (don't ask why) and/or put some custom button and do logging on OnClick event. This is just to eliminate possibility that problem is in your app page. –  Vedran Rasol Feb 7 '12 at 20:56
    
Also: The AppPool user needs to be in the Performance Log Users group –  Dennis G Feb 3 at 11:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.