I have the following simple code:
SPDiagnosticsService diagnosticsService = SPDiagnosticsService.Local;
SPDiagnosticsCategory cat = diagnosticsService.Areas["SharePoint Foundation"].Categories["Unknown"];
string format = "Test trace logging for category {0} in area {1}";
diagnosticsService.WriteTrace(1, cat, TraceSeverity.Medium, format, cat.Name, cat.Area.Name);
I only want to write to the SharePoint ULS Logs. But this does not work. What could be the reason?
UPDATE:
Oh sorry!! I get no entries in the ULS Logs. ULS Logs are generated, but mine are not written to the Logs. All categories in diagnostics logging configuration in the CA are set to Trace level Medium and Event Level Information. There is no exception thrown, too. The code runs fine when I run it via F5 and step through it.
SOLUTION FOUND!
The AppPool Account has to be in the local Performance Log Users group! I have blogged about it here, too: http://www.bog1.de/2015/03/es-ist-nicht-moglich-in-die-uls-logs-zu-schreiben-performance-log-users/
I couldn't find the reason why it did not work on the vm but I decided to setup a fresh one and to test after each step if my solution works.
It seems to be a config issue.
With the new machine everything works fine.