During a recent project I faced with a problem :
I had a form whose content needed to be saved to an Oracle DB.
I also had a fall back code which in case of the failure of the former would write the same data to a SQL server DB as a temporary repository of the form data.
For some reasons my code to write to a Oracle DB were not going through and neither was my code to write to a SQL server temporary table.
Automatically I was checking the Event Log and tried to figure out what was wrong.
I had elaborate Event Logging code all over the project to help me understand what is going on under the hood, which will help me debug. But alas, there was no new log created for the web app at all!!!
There were no relevant entries in the Application Log as well.
I tried concentrating on the fix to the original problem, and tried many random SQL Server and Oracle fixes but I was unable to reach a solution. This went on throughout the day..
After a lot of misses I finally decided to fix the Event Log issue first… (And how prophetic was it!!!)
So I was already aware of the cause, ASP.Net runs on a lower privilege, which prevents it to write to the logs.. I had faced it earlier in a SharePoint project and had added a code to raise the privilege of the particular method which writes to the log.. Should I apply that again? I thought of digging deeper… After a lot of scouring through the net in MSDN, StackOverflow and multiple other blogs.. I found out that everybody was suggesting a different approach.. Then I came across a MSDN kb article which gave 2 possible fixes, Firstly, to apply some registry hacks which I am sure most IT admins would not allow me to do on a prod server.. and Secondly to add the Event Logs and Event Source Names manually.. There was a third way too, that to raise the privilege of the ASP.net account to a higher one.. or to use a admin account as the App pool account.. But then the reason ASP.net was designed to run on a lower privilege was for some reasons.. right? Namely from stopping access to directories outside the current one or to access other resources etc.. That would be defeated.
I liked the second approach and developed a small tool to create the Event Logs and Event Source Names from a Config file.. And lo the event logging was working for my website… So what was happening? It appears that writing a new event is a common activity which a less privileged thread can perform, but Creating Event Logs and Event Source Names is considered to be Admin tasks, which the ASP.net account is not capable of doing.
So after the Event logging issue was sorted out I now concentrated solving the original problem.. The logs clearly showed that the Oracle connection could not be opened due to some tnsnames.ora issue, and the fall back insertion was failing because the SP name which was hardcoded in the app had an extra “_” (underscore) character..
Moral of the story: Event Logging should be set up as early as possible.