public IHttpActionResult WriteToLog(string app, [FromBody]LogEntryLevelModel logEntry) 
                                                                        
        {
            IHttpActionResult result = null;
            //If OccuredOn in post object is not valid format, C# defaults to {1/1/0001 12:00:00 AM}            

            if (ModelState.IsValid)
            {
                //LogMessage(app, logEntry.logLevel, logEntry);

                //Is there a more compact way to build the AppLogEntryModel as an extension of the original logEntry parameter, plus the string app?
                AppLogEntry queueEntry = new AppLogEntry();
                queueEntry.App = app;
                queueEntry.Level = logEntry.logLevel;
                queueEntry.OccurredOn = logEntry.occuredOn;
                queueEntry.Message = logEntry.message;

                //Consumer.Notify(queueEntry);
                Observer.OnNext(queueEntry);

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Accepted);
                result = new ResponseMessageResult(response);
            }
            else
            {
                result = BadRequest("Missing required details.");
            }

            return result;
        }
        public IHttpActionResult WriteToLog(string app, LogLevel logLevel, [FromBody]LogEntryModel logEntry) 
        
        {
            IHttpActionResult result = null;
            //If OccuredOn in post object is not valid format, C# defaults to {1/1/0001 12:00:00 AM}            

            if (ModelState.IsValid)
            {
                //LogMessage(app, logLevel, logEntry);

                //Repetition w/ other post action, how to dry code with slight variation on accessing logLevel
                AppLogEntry queueEntry = new AppLogEntry();
                queueEntry.App = app;
                queueEntry.Level = logLevel;
                queueEntry.OccurredOn = logEntry.occuredOn;
                queueEntry.Message = logEntry.message;

                //Consumer.Notify(queueEntry);
                Observer.OnNext(queueEntry);

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Accepted);
                result = new ResponseMessageResult(response);
            }
            else
            {
                result = BadRequest("Missing required details.");
            }

            return result;
        }
Пример #3
0
 private void LogMessage(AppLogEntry logEntry)
 {
     switch (logEntry.Level)
     {
         case LogLevel.Info:
             Log.InfoFormat("Message from {0} received at {1} : {2}", logEntry.App, logEntry.OccurredOn, logEntry.Message);
             break;
         case LogLevel.Warn:
             Log.WarnFormat("Message from {0} received at {1} : {2}", logEntry.App, logEntry.OccurredOn, logEntry.Message);
             break;
         case LogLevel.Debug:
             Log.DebugFormat("Message from {0} received at {1} : {2}", logEntry.App, logEntry.OccurredOn, logEntry.Message);
             break;
         case LogLevel.Error:
             Log.ErrorFormat("Message from {0} received at {1} : {2}", logEntry.App, logEntry.OccurredOn, logEntry.Message);
             break;
         case LogLevel.Fatal:
             Log.FatalFormat("Message from {0} received at {1} : {2}", logEntry.App, logEntry.OccurredOn, logEntry.Message);
             break;
     }
 }
 private void Cache(AppLogEntry appLogEntry)
 {
     errorCache.Add(appLogEntry);
     context.Clients.All.updateCount(errorCache.Count);            
 }