I'm trying to do system log and I keep getting this error. The logger object is Clearly instialized.
Object reference not set to an instance of an object.
Source File: C:\Users\Victor\DEV\chams\repos-development\confirm-me-api-1\Utility\AuditLogAttribute.cs. Line: 65
using ConfirmMeAPI.Models;
using Newtonsoft.Json;
using System;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web.Mvc;
using ActionFilterAttribute = System.Web.Mvc.ActionFilterAttribute;
namespace ConfirmMeAPI.Utility
{
public class AuditLogAttribute : ActionFilterAttribute
{
cfmWS.WebService _cfm = new cfmWS.WebService();
GeolocationResponse _geolocation = new GeolocationResponse();
Logger _logger = new Logger();
private readonly HttpClient _httpClient;
string baseurl;
public AuditLogAttribute()
{
baseurl = "http://ip-api.com";
_httpClient = new HttpClient();
_httpClient.BaseAddress = new Uri(baseurl);
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
public override void OnActionExecuting(ActionExecutingContext context)
{
try
{
...
}
catch (Exception ex)
{
/* THE ERROR LINE */ _logger.LogError(ex.ToString() + ex.InnerException.ToString() + ex.StackTrace.ToString());
}
}
}
}