title: Event Log C# - Cannot open log Application on machine, Win32 Exception: Access is denied
body: <p>I am trying to view the Event Viewer as an operational Dashboard to report on any warnings and errors. I am using C# MVC 5 and I am using system.diagnostics. When I try to call the information on the event viewer I am getting the error:</p>
  <pre><code>'Cannot open log Application on machine &quot;My Machine name&quot;.  Win32 Exception is denied'.
  </code></pre>
  <p>I suspect its a permissions issue but whether I amend this on the server or inside my application I am unsure.</p>
  <p>My code is below:</p>
  <pre><code> EventLog log = new EventLog(&quot;Application&quot;, &quot;MYSERVERNAME&quot;);
          int cutoff = 100;
          var events = new List&lt;EventLogEntry&gt;();
  
          var WarningsNo = 0;
          var ErrorsNo = 0;
  
          DTO.Logs LogNo = new DTO.Logs();
          DTO.ErrorDetails e = new DTO.ErrorDetails();
          List&lt;DTO.ErrorDetails&gt; errorDetails = new List&lt;DTO.ErrorDetails&gt;();
  
          for (int i = log.Entries.Count - 1; i &gt;= 0; i--)
          {
              var next = log.Entries[i];
              events.Add(next);
              if (events.Count == cutoff)
                  break;
          }
  
  
          return Json(errorDetails, JsonRequestBehavior.AllowGet);
  </code></pre>