Beispiel #1
0
        static string DefaultEventDataItemFormatter(EventDataItem logItem)
        {
            string htmlMessage = logItem.HtmlMessage.Replace("\n", "");

            return(String.Format("l2\ttime\t{0:s}\tcode\t{1}\tmessage\t{2}",
                                 logItem.EventTimeUtc,
                                 logItem.EventCode,
                                 htmlMessage));
        }
Beispiel #2
0
        void WriteEventDataItem(EventDataItem logItem, LogCategory category, ReaderWriterLock lockObject,
                                EventDataItemFormatter formatter)
        {
            if (logItem == null)
            {
                throw new ArgumentNullException("logItem");
            }

            if (lockObject == null)
            {
                throw new ArgumentNullException("lockObject");
            }

            if (formatter == null)
            {
                throw new ArgumentNullException("formatter");
            }

            try
            {
                //using (Impersonation.Impersonate())
                {
                    // Archive last day's log files.
                    if (!File.Exists(String.Format("{0}.zip", GetLogPath(logItem.EventTimeUtc, LogCategory.Event))))
                    {
                        ArchiveLogFiles(logItem.EventTimeUtc.AddDays(-1));
                    }

                    lockObject.AcquireWriterLock(TimeSpan.FromMilliseconds(250));

                    using (StreamWriter writer = new StreamWriter(GetLogPath(logItem.EventTimeUtc, category), true))
                    {
                        writer.WriteLine(formatter(logItem));
                    }
                }
            }
            catch (Exception e)
            {
                ErrorTrace.Trace(TraceLevel.Error, e);
            }
            finally
            {
                if (lockObject.IsWriterLockHeld)
                {
                    lockObject.ReleaseWriterLock();
                }
            }
        }
Beispiel #3
0
        static EventDataItemCollection ParseEventDataItems(string logText)
        {
            EventDataItemCollection result = new EventDataItemCollection();

            MatchCollection matches = _eventDataItemParser.Matches(logText);

            if (matches != null)
            {
                foreach (Match match in matches)
                {
                    EventDataItem item = new EventDataItem();
                    item.EventTimeUtc = DateTime.Parse(match.Groups["time"].Value);
                    item.EventCode    = Int32.Parse(match.Groups["code"].Value);
                    item.HtmlMessage  = match.Groups["message"].Value;
                    result.Add(item);
                }
            }

            return(result);
        }
Beispiel #4
0
 void ILoggingDataService.AddEvent(EventDataItem eventData)
 {
     ThreadPool.QueueUserWorkItem(new WaitCallback(AddEventDataItemWorker),
                                  new WriterThreadParams <EventDataItem>(eventData, LogCategory.Event, _eventLock));
 }