none
How to create an event log with asp.net mvc 5 application? RRS feed

  • Question

  • I've been trying to figure out how to create an event log in an asp.net mvc 5 application but I haven't been able to find a good tutorial. Are there any tutorials that can help or could you explain to me how to go about how to log events in my application? 

    To give an example of one of the functions in my application, this is a create function:

    public ActionResult Create()
            {
                ViewBag.AccountId = new SelectList(db.Accounts, "Id", "Name");
                return View();
            }
    
            [HttpPost]
            [ValidateAntiForgeryToken]
            public async Task<ActionResult> Create([Bind(Include = "Id,AccountId,IsActive,InitalBalance,Comments")] ChartOfAccount chartOfAccount)
            {
                chartOfAccount.CreatedOn = DateTime.Now;
                chartOfAccount.CreatedBy = "Administrator";
                var account = db.Accounts.FirstOrDefault(x => x.Id == chartOfAccount.AccountId);
    
                var isInChartOfAccounts = db.ChartOfAccounts.FirstOrDefault(x => x.AccountId == chartOfAccount.AccountId);
    
                if (isInChartOfAccounts != null)
                {
                    TempData["Message"] = "This account has already been created.";
                    return RedirectToAction("Index");
                }
                
                chartOfAccount.AccountCode = GetAccountCode(account);
                if (ModelState.IsValid)
                {
                    db.ChartOfAccounts.Add(chartOfAccount);
                    await db.SaveChangesAsync();
                    return RedirectToAction("Index");
                }
    
                ViewBag.AccountId = new SelectList(db.Accounts, "Id", "Name", chartOfAccount.AccountId);
                return View(chartOfAccount);
            }


    • Moved by CoolDadTx Wednesday, March 8, 2017 3:40 PM ASP.NET related
    Sunday, March 5, 2017 8:44 PM

All replies

  • ASP.Net has it's own dedicated main Forum. You are better of asking your questions there:
    https://forums.asp.net/

    With exception logging and exposure in Web Applications, security concerns are often very important.


    Remember to mark helpfull answers as helpfull and close threads by marking answers.

    Sunday, March 5, 2017 10:59 PM
  • thank you for pointing me there, I'll make sure to ask in the asp.net forum
    Sunday, March 5, 2017 11:28 PM
  • Hi Ishiii101,

    I would suggest you use Enterprise Library Logging Application Block.

    The Enterprise Library Logging Application Block simplifies the implementation of common logging functions. Developers can use the Logging Block to write information to a variety of locations:

    • The event log
    • An e-mail message
    • A database
    • A message queue
    • A text file
    • A Windows Management Instrumentation (WMI) event
    • Custom locations using application block extension points

    For more details, please refer to https://msdn.microsoft.com/en-us/library/ff647240.aspx

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 8, 2017 2:52 AM