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:

    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?

  • 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?? – BlueSoul Feb 8 '12 at 11:12
  • 1
    -- 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
  • I face the same problem for a really long time. It feels like it's an infrastructure problem. My findings: 1) mostly, I have this problem with SharePoint 2013 Foundation 2) I have one farm with two servers one of which has this problem and the other doesn't. 3) it does not matter whether Logging category exists or not 4) We are facing this problem using both very old loggers that we used for years and with different, new ones. 5) logging with Elevated privileges changes nothing 6) running logger method from PowerShell or console it works perfectly fine, but does not run from SPLogLevel or w3wp – Denis Molodtsov May 7 '15 at 15:55
  • I wonder if it has something to do with a SharePoint trial period that expired... – Denis Molodtsov May 7 '15 at 16:37

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.

| improve this answer | |
  • 1
    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
  • 1
    Also: The AppPool user needs to be in the Performance Log Users group – Dennis G Feb 3 '14 at 11:50

Have you tried running your logging code using elevated privileges?

SPSecurity.RunWithElevatedPrivileges(delegate() {
       new SPDiagnosticsCategory("My Errors", TraceSeverity.Monitorable, EventSeverity.Error),
       TraceSeverity.Monitorable, "Exception occured: {0}", new object[] { "NOT!" });
| improve this answer | |
  • I've tried it. it does not help at all – Denis Molodtsov May 7 '15 at 15:50

In Autofac registration module, dont use SPUtility.GetVersionedGenericSetupPath and any other methods which internally can use uls logging

This cause stopping any custom SPDiagnosticsServiceBase based loggers to stop work

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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