public void ZeroTest()
        {
            var webevent = new W3CEvent();

            webevent.TimeTaken = 0;
            Assert.Equal(0, webevent.TimeTakenInSeconds());
        }
Example #2
0
        private LogRecord Map(AppInfo app, W3CEvent ev)
        {
            var lvl = LogRecord.ELogLevel.Info;

            if (ev.sc_status.StartsWith("4", StringComparison.Ordinal))
            {
                lvl = LogRecord.ELogLevel.Warning;
            }
            else if (ev.sc_status.StartsWith("5", StringComparison.Ordinal))
            {
                lvl = LogRecord.ELogLevel.Error;
            }

            return(new LogRecord {
                TimeUtc = ev.dateTime,
                ApplicationPath = app.Path,
                LoggerName = "IISLog",
                LogLevel = lvl,
                ProcessId = app.ProcessIds.FirstOrDefault(),
                Server = SharedInfoAboutApps.MachineName,
                AdditionalFields = new Dictionary <string, object>()
                {
                    { "HttpStatusCode", string.Format("{0}{1}{2}", ev.sc_status, string.IsNullOrEmpty(ev.sc_substatus) ? string.Empty : "." + ev.sc_substatus,
                                                      string.IsNullOrEmpty(ev.sc_win32_status) ? string.Empty : "." + ev.sc_win32_status) },
                    { "ClientIP", ev.c_ip },
                    { "Url", string.Format("{0}{1}{2}", ev.cs_uri_stem, ev.cs_uri_query != null ? "?" : string.Empty, ev.cs_uri_query) }
                }
            });
        }
        public void PassingTest()
        {
            var webevent = new W3CEvent();

            webevent.TimeTaken = 1000;
            Assert.Equal(1, webevent.TimeTakenInSeconds());
        }
        private W3CEvent CreateW3CEvent(string uriStem, int timeTaken)
        {
            W3CEvent evt = new W3CEvent();

            evt.cs_uri_stem = uriStem;
            evt.time_taken  = timeTaken.ToString();
            return(evt);
        }
Example #5
0
 public static DateTimeOffset UtcTime(this W3CEvent w3cEvent)
 {
     return(new DateTimeOffset(w3cEvent.Date.Year,
                               w3cEvent.Date.Month,
                               w3cEvent.Date.Day,
                               w3cEvent.Time.Hour,
                               w3cEvent.Time.Minute,
                               w3cEvent.Time.Second,
                               w3cEvent.Date.Offset));
 }
Example #6
0
        public W3CEvent Parse(string line, W3CFieldMap fieldMap)
        {
            var returnValue     = new W3CEvent();
            var fieldValueIndex = 0;

            foreach (var fieldValue in line.Split(' '))
            {
                if (fieldMap.ContainsKey(fieldValueIndex))
                {
                    var fieldInfo = fieldMap[fieldValueIndex];
                    fieldInfo.FieldInfo.SetValue(returnValue, fieldInfo.Convertor.Convert(fieldValue));
                }
                fieldValueIndex += 1;
            }

            return(returnValue);
        }
Example #7
0
 public static DateTimeOffset ToLocalTime(this W3CEvent w3cEvent)
 {
     return(UtcTime(w3cEvent).ToLocalTime());
 }
Example #8
0
 public static int TimeTakenInSeconds(this W3CEvent w3cEvent) => w3cEvent.TimeTaken / 1000;