c#


How can i write to the windows event log using C# (I'm getting some kind of error)?


I have written:
.
.
.
//Log exception to the event log
if (!EventLog.SourceExists("PodaHIS")) {
EventLog.CreateEventSource("PodaHIS", "Application");
}
EventLog eventLog = new EventLog();
eventLog.Log = "Application";
eventLog.Source = "PodaHIS";
eventLog.WriteEntry(error.ToString(), EventLogEntryType.Error);
I have also enabled read permission to LOCALMACHINE\ASPNET.
And in return i get:
The source was not found, but some or all event logs could not be searched. Inaccesible logs: Security.
Does anyone know why this is happening?
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\EventLog
What is need to do was grant the "Security" sub key of the EventLog Key read permission. After that i restarted my IIS.
this kb artical explains the steps required to give your asp process the correct security rights to write to the event log...
kb
If you have permission on the box that you want to write the event log to, then you can run a script that I wrote.
I think that a higher level of access is required to create a source in the event log. It's possible that the reference to Security log is coincidental and it is just reporting that as a possible cause. If you go in as an administrator and create the PodaHIS source yourself, you might then find that it can write to it.
What it your deployment environment? If it is Vista/Server 2008 then adding worker account into Administrators group won't work due to UAC.
This link explains the problem in details.
But I would recommend try creating an event source manually so ASPNET won't need to create it...

Related Links

JavaScript function return boolean in C#
Ajax.BeginForm: What to return from controller to prevent page refresh?
Global access to variables and properties for a C# Excel add in
dynamic data to Jquery code in ASP .Net Visual Studio
c# mysql wait for previous query to finish
How to embed a c# app to SP website without Microsoft.SharePoint.Client.dll?
String manipulation to create email address from first and last name at least 4 times
The name does not exist in the current context (specific case)
Image upload quality bad
How to redirect a WCF to an external URL (Google AdWords Sign In) and handle the response?
How to diagnose a corrupted suffix pattern in a mixed managed/unmanaged x32 .NET application
How to work with memory I did not allocate
Using Autofac to inject a dependency into the Main entry point in a console app
How to bind data collection with Custom Template
Implementing filters using check boxes
How to change the gridview row color?

Categories

HOME
sql-server-2014
ubuntu-14.04
opengl-es
sdk
confluence-rest-api
ms-access-2010
clip-path
google-app-maker
oms
mongoimport
expo
tag-cloud
template10
powerpivot
windows-phone
orange
ampscript
ithit-webdav-server
android-wear-2.0
rancher
expressionengine
orgchart
stack-trace
drombler-fx
sphinx4
undo
edsdk
akamai
login-required
matlab-compiler
certbot
libconfig
byobu
ngrok
jslider
linkurious
wicket-tester
python-venv
gridgain
xmldom
px4
nservicebus6
dynatable
catalyst
blackberry-webworks
altova
vitamio
avaudiorecorder
jsondoc
random-sample
first-order-logic
stereotype
vectordrawable
gcc-warning
jeet-grid
skview
pymol
google-experiments
uiblureffect
information-hiding
xts
drawable
satisfiability
infor-eam
db2-connect
codio
ardor3d
tlbimp
qgraphicsscene
wpd
feincms
netzke
aspmenu-control
wxperl
mysql-connector
jqueryi-ui-buttonset
maven-eclipse-plugin
log-shipping
pex-and-moles
html5-animation
xcdatamodel
helios
datadude
unauthorized

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App