Action Method
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
LogError("lok", "lok2", "lok3");
return View();
}
LogError Method
private void LogError(string transactionId, string sAmountPaid, string deviceId)
{
// Creating the source, which will generate error
if (!EventLog.SourceExists("MyApplication"))
{
//Creating log, where error will be logged
EventLog.CreateEventSource("MyApplication", "MyLog");
}
// Creating object of EventLog to log error
var myAppLog = new EventLog { Source = "MyApplication" };
//Writing error to log
myAppLog.WriteEntry(transactionId + sAmountPaid + deviceId);
}
When I run Home page it always shows "Error. An error occurred while processing your request.".I suspect this is due to unable to create log on "Event Viewer".When I run above code on local host it's working fine.But when I publish it into IIS server on Windows Server 2012 it's giving above error.
My Question: Should I enable any kind of permission for create log on Event viewer.If so how to do that ? My IIS is working on Windows Server 2012.
This has been asked before. The following link is to that discussion.
Writing to an event log in ASP.NET on Windows Server 2008 IIS7
You will need to give the application the privileges to write to the Windows Event Log.
However, it is not recommended because of several reasons.
Alternatives to logging into windows event log: