public void LogData(AppLogEntry log)
 {
     // TODO: Save the request log entry into database
     using (HttpWebLogger logger = new HttpWebLogger())
     {
         logger.LogWebRequest(log);
     }
 }
 /// <summary>
 /// FormatRequest method
 /// </summary>
 /// <remarks>This FormatRequest method will take ref of AppLogEntry object, ref of HttpContext object </remarks>
 /// <param name="appLogEntry"></param>
 /// <param name="context"></param>
 /// <param name="requestBodyText"></param>
 private void FormatRequest(ref AppLogEntry appLogEntry, ref HttpContext context, string requestBodyText)
 {
     _appLogEntry.AppMessageEntryId = Guid.NewGuid().ToString();
     _appLogEntry.ApplicationName   = "Inventory";
     _appLogEntry.User               = GetUserName(context.User.Claims);
     _appLogEntry.Machine            = Environment.MachineName;
     _appLogEntry.RequestContentType = context.Request.ContentType;
     _appLogEntry.RequestContentBody = requestBodyText;
     _appLogEntry.RequestIpAddress   = context.Connection.LocalIpAddress.ToString();
     _appLogEntry.RequestMethod      = context.Request.Method;
     _appLogEntry.RequestHeaders     = JsonConvert.SerializeObject(context.Request.Headers.ToList <KeyValuePair <string, Microsoft.Extensions.Primitives.StringValues> >(), Newtonsoft.Json.Formatting.Indented);
     _appLogEntry.RequestTimestamp   = DateTime.Now;
     _appLogEntry.RequestUri         = context.Request.GetDisplayUrl();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// LogWebRequest Method for saving AppLogEntry details into DB
        /// </summary>
        /// <remarks>This LogWebRequest method object will invoke LogManagerDbContext.SaveChanges which will save details into DB</remarks>
        /// <param name="appLogEntry"></param>
        #region Log Request and Response

        public void LogWebRequest(AppLogEntry appLogEntry)
        {
            try
            {
                using (LogManagerDbContext db = new LogManagerDbContext())
                {
                    if (appLogEntry != null)
                    {
                        AppMessageLog msg = new AppMessageLog();
                        msg.AppMessageEntryId = appLogEntry.AppMessageEntryId;
                        msg.ApplicationName   = appLogEntry.ApplicationName;
                        msg.User                 = appLogEntry.User;
                        msg.Machine              = appLogEntry.Machine;
                        msg.RequestIpAddress     = appLogEntry.RequestIpAddress;
                        msg.RequestContentType   = appLogEntry.RequestContentType;
                        msg.RequestContentBody   = appLogEntry.RequestContentBody;
                        msg.RequestUri           = appLogEntry.RequestUri;
                        msg.RequestMethod        = appLogEntry.RequestMethod;
                        msg.RequestRouteTemplate = appLogEntry.RequestRouteTemplate;
                        msg.RequestRouteData     = appLogEntry.RequestRouteData;
                        msg.RequestHeaders       = appLogEntry.RequestHeaders;
                        msg.RequestTimestamp     = appLogEntry.RequestTimestamp;
                        msg.ResponseContentType  = appLogEntry.ResponseContentType;
                        msg.ResponseContentBody  = appLogEntry.ResponseContentBody;
                        msg.ResponseStatusCode   = appLogEntry.ResponseStatusCode;
                        msg.ResponseHeaders      = appLogEntry.ResponseHeaders;
                        msg.ResponseTimestamp    = appLogEntry.ResponseTimestamp;

                        db.AppMessageLog.Add(msg);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                disposedValue = true;
            }
        }
 /// <summary>
 /// LoggerMiddleware Constructor
 /// </summary>
 /// <remarks>This Constructor will take RequestDelegate</remarks>
 /// <param name="next"></param>
 public LoggerMiddleware(RequestDelegate next)
 {
     _next        = next;
     _appLogEntry = new AppLogEntry();
 }