0

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

1 Answer 1

0

Basically you're missing an assembly reference that you need to add to your project.

'EventLog' is part of system.diagnostics namespace which is part of System.dll assembly, make sure that this assembly is referenced in your project.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.