Example #1
0
        /// <summary>
        /// Passes the LogItem to all configured loggers for logging
        /// </summary>
        /// <param name="item">LogItem to log</param>
        public void Log(ApplicationLogs item)
        {
            try
            {
                if (!isInitialized)
                {
                    Initialize();
                }

                if (LoggingMode.Trim().ToUpperInvariant() == LogMode.Asynchronous.ToString().Trim().ToUpperInvariant())
                {
                    AddToQueue(item);
                }
                else
                {
                    foreach (KeyValuePair <int, ILogger> keyValuePair in targetLoggers)
                    {
                        try
                        {
                            keyValuePair.Value.Log(item);
                            break; // If no exception stop targetting the remaining loggers
                        }
                        catch (Exception)
                        {
                            continue; // If exception occured in the higher priority logger, process next logger
                        }
                    }
                }
            }
            catch (Exception)
            {
                // The exception throw is suppressed so that applications dont get runtime errors
                // if logging fails for any reason
            }
        }
Example #2
0
        protected override void Append(LoggingEvent loggingEvent)
        {
            ApplicationLogs appLogs = new ApplicationLogs();

            appLogs.Message = loggingEvent.RenderedMessage;
            //appLogs.DateTimeStamp = DateTimeOffset.Now.UtcDateTime;
            //appLogs.UserAgent = (log4net.LogicalThreadContext.Properties["UserAgent"] != null) ? log4net.LogicalThreadContext.Properties["UserAgent"].ToString() : string.Empty;
            //appLogs.OS = (log4net.LogicalThreadContext.Properties["OS"] != null) ? log4net.LogicalThreadContext.Properties["OS"].ToString() : string.Empty;
            //appLogs.Device = (log4net.LogicalThreadContext.Properties["Device"] != null) ? log4net.LogicalThreadContext.Properties["Device"].ToString() : string.Empty;
            //appLogs.OSVersion = (log4net.LogicalThreadContext.Properties["OSVersion"] != null) ? log4net.LogicalThreadContext.Properties["OSVersion"].ToString() : string.Empty;
            //appLogs.BrowserVersion = (log4net.LogicalThreadContext.Properties["BrowserVersion"] != null) ? log4net.LogicalThreadContext.Properties["BrowserVersion"].ToString() : string.Empty;

            appLogs.Thread       = loggingEvent.ThreadName;
            appLogs.LogLevelType = loggingEvent.Level.Name;
            appLogs.LoggerName   = loggingEvent.LoggerName;
            appLogs.Exception    = loggingEvent.ExceptionObject;
            //appLogs.Environment = (log4net.LogicalThreadContext.Properties["Environment"] != null) ? log4net.LogicalThreadContext.Properties["Environment"].ToString() : string.Empty;
            //appLogs.User = (log4net.LogicalThreadContext.Properties["User"] != null) ? log4net.LogicalThreadContext.Properties["User"].ToString() : string.Empty;
            //appLogs.UrlReferrer = (log4net.LogicalThreadContext.Properties["UrlReferrer"] != null) ? log4net.LogicalThreadContext.Properties["UrlReferrer"].ToString() : string.Empty;
            //appLogs.ClientBrowser = (log4net.LogicalThreadContext.Properties["ClientBrowser"] != null) ? log4net.LogicalThreadContext.Properties["ClientBrowser"].ToString() : string.Empty;
            //appLogs.ClientIP = (log4net.LogicalThreadContext.Properties["ClientIP"] != null) ? log4net.LogicalThreadContext.Properties["ClientIP"].ToString() : string.Empty;
            //appLogs.URL = log4net.LogicalThreadContext.Properties["URL"].ToString(); //(log4net.LogicalThreadContext.Properties["URL"] != null || log4net.LogicalThreadContext.Properties["URL"].ToString() == string.Empty) ? log4net.LogicalThreadContext.Properties["URL"].ToString() : string.Empty;
            //appLogs.ApplicationIdentifier = (log4net.LogicalThreadContext.Properties["ApplicationIdentifier"] != null) ? log4net.LogicalThreadContext.Properties["ApplicationIdentifier"].ToString() : string.Empty;
            //appLogs.Source = (log4net.LogicalThreadContext.Properties["Source"] != null) ? log4net.LogicalThreadContext.Properties["Source"].ToString() : string.Empty;
            //appLogs.RequestObject = (log4net.LogicalThreadContext.Properties["RequestObject"] != null) ? log4net.LogicalThreadContext.Properties["RequestObject"].ToString() : string.Empty;
            //appLogs.EventName = (log4net.LogicalThreadContext.Properties["EventName"] != null) ? log4net.LogicalThreadContext.Properties["EventName"].ToString() : string.Empty;
            appLogs.StackTrace = (log4net.LogicalThreadContext.Properties["StackTrace"] != null) ? log4net.LogicalThreadContext.Properties["StackTrace"].ToString() : string.Empty;
            // TODO : remove circular dependency between repository and logging

            /*
             * _dbRepository = new MongoDbRepository<ApplicationLogs>("applogs");
             * _dbRepository.Insert(appLogs);
             */
        }
Example #3
0
        public HttpResponseMessage WriteLog(string ClientName, string LogData)
        {
            //log to database
            using (Models.SQL.tasktserverContext dbContext = new tasktserverContext())
            {
                try
                {
                    ApplicationLogs log = new ApplicationLogs();
                    log.LoggedBy = ClientName;
                    log.Message  = LogData;
                    log.Type     = "WORKER LOG";
                    log.LoggedOn = DateTime.Now;
                    dbContext.ApplicationLogs.Add(log);
                    dbContext.SaveChanges();
                }
                catch (Exception)
                {
                    return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
                }
            }


            // Save Code will be here
            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
        protected async override void Append(LoggingEvent loggingEvent)
        {
            ApplicationLogs appLogs = new ApplicationLogs();

            appLogs.Message               = loggingEvent.RenderedMessage;
            appLogs.Timestamp             = loggingEvent.TimeStamp;
            appLogs.Thread                = loggingEvent.ThreadName;
            appLogs.LogLevelType          = loggingEvent.Level.Name;
            appLogs.LoggerName            = loggingEvent.LoggerName;
            appLogs.Message               = loggingEvent.RenderedMessage;
            appLogs.Exception             = loggingEvent.ExceptionObject;
            appLogs.Environment           = (log4net.LogicalThreadContext.Properties["Environment"] != null) ? log4net.LogicalThreadContext.Properties["Environment"].ToString() : string.Empty;
            appLogs.User                  = (log4net.LogicalThreadContext.Properties["User"] != null) ? log4net.LogicalThreadContext.Properties["User"].ToString() : string.Empty;
            appLogs.UrlReferrer           = (log4net.LogicalThreadContext.Properties["UrlReferrer"] != null) ? log4net.LogicalThreadContext.Properties["UrlReferrer"].ToString() : string.Empty;
            appLogs.ClientBrowser         = (log4net.LogicalThreadContext.Properties["ClientBrowser"] != null) ? log4net.LogicalThreadContext.Properties["ClientBrowser"].ToString() : string.Empty;
            appLogs.ClientIP              = (log4net.LogicalThreadContext.Properties["ClientIP"] != null) ? log4net.LogicalThreadContext.Properties["ClientIP"].ToString() : string.Empty;
            appLogs.URL                   = (log4net.LogicalThreadContext.Properties["URL"] != null) ? log4net.LogicalThreadContext.Properties["URL"].ToString() : string.Empty;
            appLogs.ApplicationIdentifier = (log4net.LogicalThreadContext.Properties["ApplicationIdentifier"] != null) ? log4net.LogicalThreadContext.Properties["ApplicationIdentifier"].ToString() : string.Empty;
            appLogs.Source                = (log4net.LogicalThreadContext.Properties["Source"] != null) ? log4net.LogicalThreadContext.Properties["Source"].ToString() : string.Empty;
            appLogs.RequestObject         = (log4net.LogicalThreadContext.Properties["RequestObject"] != null) ? log4net.LogicalThreadContext.Properties["RequestObject"].ToString() : string.Empty;
            appLogs.EventName             = (log4net.LogicalThreadContext.Properties["EventName"] != null) ? log4net.LogicalThreadContext.Properties["EventName"].ToString() : string.Empty;
            appLogs.StackTrace            = (log4net.LogicalThreadContext.Properties["StackTrace"] != null) ? log4net.LogicalThreadContext.Properties["StackTrace"].ToString() : string.Empty;
            appLogs.ResponseObject        = (log4net.LogicalThreadContext.Properties["ResponseObject"] != null) ? log4net.LogicalThreadContext.Properties["ResponseObject"].ToString() : string.Empty;
            //appLogs.UserAgent = (log4net.LogicalThreadContext.Properties["UserAgent"] != null) ? log4net.LogicalThreadContext.Properties["UserAgent"].ToString() : string.Empty;
            //appLogs.OS = (log4net.LogicalThreadContext.Properties["OS"] != null) ? log4net.LogicalThreadContext.Properties["OS"].ToString() : string.Empty;
            //appLogs.Device = (log4net.LogicalThreadContext.Properties["Device"] != null) ? log4net.LogicalThreadContext.Properties["Device"].ToString() : string.Empty;
            //appLogs.OSVersion = (log4net.LogicalThreadContext.Properties["OSVersion"] != null) ? log4net.LogicalThreadContext.Properties["OSVersion"].ToString() : string.Empty;
            //appLogs.BrowserVersion = (log4net.LogicalThreadContext.Properties["BrowserVersion"] != null) ? log4net.LogicalThreadContext.Properties["BrowserVersion"].ToString() : string.Empty;
            //azureStorageTableAdapter.InsertTable<ApplicationLogs>("ApplicationLogs", appLogs);
            await azureStorageTableAdapter.InsertAsync(appLogs);
        }
        public async Task <bool> RegisterApplicationLog(ApplicationLogs log)
        {
            string logmessage = JsonConvert.SerializeObject(log);
            string exchange   = _configuration.GetSection("MessageQuque").GetSection("Applicationlogs").GetSection("exchangene").Value;
            string routingkey = _configuration.GetSection("MessageQuque").GetSection("Applicationlogs").GetSection("routingkey").Value;

            return(await Task.Run(() => SendMessagetoExchange(exchange, routingkey, logmessage)));
        }
Example #6
0
        /// <summary>
        /// Logs the given message. Output depends on the associated
        /// log4net configuration.
        /// </summary>
        /// <param name="item">A <see cref="ApplicationLogs"/> which encapsulates
        /// information to be logged.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="item"/>
        /// is a null reference.</exception>
        public void Log(ApplicationLogs item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (!isInitalized)
            {
                Initialize();
            }

            item.LoggerName = this.LoggerName;

            switch (item.LogLevel)
            {
            case LogLevel.Fatal:
                if (IsLogLevelEnabled(item.LogLevel))
                {
                    logger.Fatal(item.Message, item.Exception);
                }
                break;

            case LogLevel.Error:
                if (IsLogLevelEnabled(item.LogLevel))
                {
                    logger.Error(item.Message, item.Exception);
                }
                break;

            case LogLevel.Warn:
                if (IsLogLevelEnabled(item.LogLevel))
                {
                    logger.Warn(item.Message, item.Exception);
                }
                break;

            case LogLevel.Info:
                if (IsLogLevelEnabled(item.LogLevel))
                {
                    logger.Info(item.Message, item.Exception);
                }
                break;

            case LogLevel.Debug:
                if (IsLogLevelEnabled(item.LogLevel))
                {
                    logger.Debug(item.Message, item.Exception);
                }
                break;

            default:
                logger.Info(item.Message, item.Exception);
                break;
            }
        }
 /// <summary>
 /// Validate the object.
 /// </summary>
 /// <exception cref="ValidationException">
 /// Thrown if validation fails
 /// </exception>
 public virtual void Validate()
 {
     if (ApplicationLogs != null)
     {
         ApplicationLogs.Validate();
     }
     if (HttpLogs != null)
     {
         HttpLogs.Validate();
     }
 }
 /// <summary>
 /// Validate the object.
 /// </summary>
 /// <exception cref="ValidationException">
 /// Thrown if validation fails
 /// </exception>
 public override void Validate()
 {
     if (ApplicationLogs != null)
     {
         ApplicationLogs.Validate();
     }
     if (HttpLogs != null)
     {
         HttpLogs.Validate();
     }
 }
Example #9
0
 /// <summary>
 /// If configuration is set to Async, adds log items to the processing queue
 /// </summary>
 /// <param name="item">LogItem to log</param>
 internal void AddToQueue(ApplicationLogs item)
 {
     try
     {
         if (LogItems.Count < MaxQueueSize)
         {
             LogItems.Enqueue(item);
         }
     }
     catch (Exception)
     {
         // Do nothing if add to Queue failed
     }
 }
Example #10
0
 private void LogEvent(ApplicationLogs log)
 {
     using (Models.SQL.tasktserverContext dbContext = new tasktserverContext())
     {
         try
         {
             log.LoggedOn = DateTime.Now;
             dbContext.ApplicationLogs.Add(log);
             dbContext.SaveChanges();
         }
         catch (Exception ex)
         {
             throw;
         }
     }
 }
Example #11
0
        private void HandleMessage(string content)
        {
            try
            {
                EmailNotificationModel emailObj = new EmailNotificationModel();
                emailObj = JsonConvert.DeserializeObject <EmailNotificationModel>(content);


                NotificationClass.SendEmail(emailObj);

                // Send Update to Log Service.
                ApplicationLogs applogs = new ApplicationLogs();
                applogs.LogMessage = emailObj.Emailfrom + "\t" + emailObj.Emailto + "\t" + emailObj.CC + "\t" + emailObj.Content;
                _queueProvider.RegisterApplicationLog(applogs);
            }
            catch
            { }
        }
Example #12
0
        /// <summary>
        /// Processes LogItems asyncronously from the queue
        /// </summary>
        internal void ProcessFromQueue()
        {
            ApplicationLogs logItem = null;

            while (LogItems.TryDequeue(out logItem))
            {
                if (logItem != null)
                {
                    // Target loggers are already ordered by PriorityOrder
                    foreach (KeyValuePair <int, ILogger> keyValuePair in targetLoggers.OrderBy(o => o.Key))
                    {
                        try
                        {
                            keyValuePair.Value.Log(logItem);
                            break; // If no exception stop targetting the remaining loggers
                        }
                        catch (Exception)
                        {
                            continue; // If exception occured in the higher priority logger, process next logger
                        }
                    }
                }
            }
        }