R – SharePoint and deployment of global.asax code


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?

Best Solution

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());


This then gets instanciated only once and we use the destructor to unregister it.

Related Question