I am trying to create a web application to read all windows events log and display into the web page. i tried it in asp.net mvc 5 its working but when I tried to execute it in a asp.net mvc 6 application is shows error.
Controller
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication1.Models;
using WebApplication1.Models.PaginationExample;
namespace WebApplication1.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
EventLog eventLog = new EventLog("Application", "nb-ahja1", "EventLoggingApp");
var model = new List<Eventlogg>();
foreach (EventLogEntry log in eventLog.Entries)
{
var demo = new Eventlogg();
demo.Source = log.Source;
demo.Id = log.EventID;
demo.Level = log.EntryType.ToString();
demo.Date = log.TimeGenerated;
demo.Category = log.Category;
model.Add(demo);
}
return View(model.OrderByDescending(x => x.Date).ToList());
}
public ActionResult About()
{
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
}
}
Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApplication1.Models
{
public class Eventlogg
{
public string Source { get; set; }
public int Id { get; set; }
public string Level { get; set; }
public DateTime Date { get; set; }
public string Category { get; set; }
}
}
View
@model List<WebApplication1.Models.Eventlogg>
@{
ViewBag.Title = "Home Page";
}
<div class="container" >
<table class="table table-hover" id="myTable">
<tr>
<td class="col-md-3"><b>Level</b></td>
<td class="col-md-3"><b>Date</b></td>
<td class="col-md-3"><b>Source</b></td>
<td class="col-md-3"><b>Id</b></td>
<td class="col-md-3"><b>Category</b></td>
</tr>
@foreach (var item in Model)
{
<tr>
<td class="col-md-3">@item.Level</td>
<td class="col-md-3">@item.Date</td>
<td class="col-md-3">@item.Source</td>
<td class="col-md-3">@item.Id</td>
<td class="col-md-3">@item.Category</td>
</tr>
}
</table>
</div>
Error
Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'EventLog' could not be found (are you missing a using directive or an assembly reference?) PocDashboard.DNX Core 5.0 C:\Users\ahja\Documents\Visual Studio 2015\Projects\AteaPoCDashboard\src\PocDashboard\Controllers\HomeController.cs 19 Active