I’m sure I’m not the first person to come up with this. Megjithatë, I haven’t noticed anyone publish a trick like this since I started paying close attention to the community last July. Kështu, Unë mendova se do të postoj atë këtë tip të shpejtë dhe të lehtë debug.
I’m working on an event receiver that started to generate this error in the 12 zgjua:
Ngarkimin dhe drejtimin Error ngjarje marrës Conchango.xyzzyEventReceiver në xyzzy, Version = 1.0.0.0, Culture = neutral, PublicKeyToken=blahbalhbalh. Additional information is below. : Object reference nuk është caktuar për një shembull të një objekti.
I didn’t know where I had introduced this bug because I had done too many things in one of my code/deploy/test cycles.
I tried this solution to get my pdb in there with hopes that SharePoint’s 12 hive would show the stack trace, but no luck. I don’t know if it’s possible and if someone does, please let me know 🙂
I know it’s possible to write your own log messages to the 12 zgjua. Frankly, I wanted something a little less scary and quicker to implement.
It occurred to me that I could at least get some basic trace information by catching and re-throwing generic exceptions like this:
mundohem { UpdateEditionDate(Prona të paluajtshme); } kap (Exception e) { hedh i ri Exception("Dispatcher, UpdateEditionDate(): Exception: [" + e.ToString() + "]."); }
This showed up in the 12 hive thusly:
Ngarkimin dhe drejtimin Error ngjarje marrës Conchango.xyzzyEventReceiver në xyzzy, Version = 1.0.0.0, Culture = neutral, PublicKeyToken=blahblahblah. Additional information is below. : Dispatcher, UpdateEditionDate(): Exception: [System.NullReferenceException: Object reference nuk është caktuar për një shembull të një objekti. at Conchango.xyzzyManagementEventReceiver.UpdateEditionDate(Pronat SPItemEventProperties) at Conchango.xyzzyManagementEventReceiver.Dispatcher(Pronat SPItemEventProperties, String eventDescription)].
That gave me all the detail I needed to track down that particular problem and I expect to use it a lot going forward.
</fund>
Better yet, incorporate a logging library like Enterprise Library or log4net and your life will be even easier.