Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Action Method

SQL
public ActionResult Index()
 {
  ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
  LogError("lok", "lok2", "lok3");
  return View();
 }


LogError Method

C#
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.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900