I want to start logging some custom messages into the ULS from my custom SharePoint code. My code is running inside list item receivers attached to some lists. I'd like to configure this logging mechanism within the application start event handler in global.asax. What's the best-practices way to deploy a SharePoint solution package that modifies global.asax?
+1
A:
I don't know about "best practice", but I would be quite keen on making the edits via code in the feature reciever.
With a line that backs up the file for later restoration.
For logging, we have used Scott hilliers code here to create a trace provider to log with.
Works a treat.
I should clarify that we use a static readonly wrapper for the trace provider
static readonly Log instance = new Log();
that registers itself with the code
SPFarm farm = SPFarm.Local;
Guid traceGuid = farm.TraceSessionGuid;
unit result = NativeMethods.RegisterTraceGuids(ControlCallback, null, ref traceGuid, 0, IntPrt.Zero, null, null, out hTraceReg);
System.Diagnostics.Debug.Assert(result==NativeMethods.ERROR_SUCCESS, "TraceRegister result = " + result.ToString());
Gah!
This then gets instanciated only once and we use the destructor to unregister it.
Nat
2008-10-29 23:38:41
Do you have pointers on how to best safely modify that file? It seems pretty scary to just find the method's opening "{" and start pushing in my code, but I guess that might be okay. I was half hoping for something like SharePoint does with web.config files, but global.asax seems easier in a way.
Chris Farmer
2008-10-30 13:55:59
Nah, it seems a bit scary to me aswell. That is why I liked the Trace Provider way, not necessary to add to the global.asax.
Nat
2008-10-30 21:24:26
I have added a http module and have been using Log4net in a complex sharepoint farm the log provider can fail at random, and then there is the fact that filtering through the ULogs is pain.
Chris Dibbs
2009-09-23 20:44:03