/// <summary> /// Processes a request with logging info. Unit testable. /// /// Returns log info in easily digestable format. /// </summary> /// <param name="json">JSON sent from client by AjaxAppender</param> /// <param name="serverSideTimeUtc">Current time in UTC</param> /// <param name="jsnlogConfiguration">Contains all config info</param> internal static List <FinalLogData> ProcessLogRequestExec(string json, LogRequestBase logRequestBase, DateTime serverSideTimeUtc, JsnlogConfiguration jsnlogConfiguration) { var logDatas = new List <FinalLogData>(); FinalLogData logData = null; try { LogRequestData logRequestData = LogMessageHelpers.DeserializeJson <LogRequestData>(json); foreach (var logItem in logRequestData.lg) { logData = null; // in case ProcessLogItem throws exception logData = ProcessLogItem(logItem, logRequestBase, serverSideTimeUtc, jsnlogConfiguration); if (logData != null) { logDatas.Add(logData); } } } catch (Exception e) { try { string message = string.Format("Exception: {0}, json: {1}, FinalLogData: {{{2}}}, logRequestBase: {{{3}}}", e, json, logData, logRequestBase); var internalErrorFinalLogData = new FinalLogData(null) { FinalMessage = message, FinalLogger = Constants.JSNLogInternalErrorLoggerName, FinalLevel = Level.ERROR }; logDatas.Add(internalErrorFinalLogData); } catch { } } return(logDatas); }
public void EnsureDefaultDateFormatAllowsJsonDeserialization() { // Arrange string configXml = @" <jsnlog serverSideMessageFormat=""{ 'utcDate': '%utcDate', 'utcDateServer': '%utcDateServer', 'date': '%date', 'dateServer': '%dateServer' }""></jsnlog>"; XmlElement xe = CommonTestHelpers.ConfigToXe(configXml); // Act var jsnlogConfiguration = XmlHelpers.DeserialiseXml <JsnlogConfiguration>(xe); List <FinalLogData> actual = LoggerProcessor.ProcessLogRequestExec( _json1, new LogRequestBase("my browser", "12.345.98.7", "http://mydomain.com/main", "", null, null, null), _dtServerUtc, jsnlogConfiguration); string messageToBeLogged = actual.FirstOrDefault().FinalMessage; var datesBag1 = LogMessageHelpers.DeserializeJson <DatesBag>(messageToBeLogged); TestDatesEqual(datesBag1.utcDate, _dtFirstLogUtc); TestDatesEqual(datesBag1.utcDateServer, _dtServerUtc); TestDatesEqual(datesBag1.date, _dtFirstLog); TestDatesEqual(datesBag1.dateServer, _dtServer); var datesBag2 = Newtonsoft.Json.JsonConvert.DeserializeObject <DatesBag>(messageToBeLogged); TestDatesEqual(datesBag2.utcDate, _dtFirstLogUtc); TestDatesEqual(datesBag2.utcDateServer, _dtServerUtc); TestDatesEqual(datesBag2.date, _dtFirstLog); TestDatesEqual(datesBag2.dateServer, _dtServer); }