Recently I came across a requirement to write logs in Sharepoint log files.
Add Microsoft.Office.Server dll in your project, you can find this dll under “\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\”.
The log files are found under \Common Files\Microsoft Shared\Web Server Extensions\12\Log\. Following line of code is used to write exception in sharepoint default log file.
Microsoft.Office.Server.Diagnostic.PortalLog.LogString(“Exception – {0} – {1} – {2}”,”User Friendly Message”,ex.Message,ex.StackTrace);
Enjoy Coding

I’m trying to log with log leve, but LogString does not support log levels, and DebugLogString does not seems to work (no logging entries in ULS).
The solution in the msdn only seems to work fpr 32-bit systems.
do you have any idea?
Hi Pete,
PortalLog.DebugLogString() does the same thing, but it allows you to specify the level of the item you are logging (either Critical, Error, Information or Verbose)
Thanks,
Ashish
Great tip! Thanks a lot!