private void InitializeTuples() { string[] manifestResourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames(); foreach (string text in manifestResourceNames) { if (text.EndsWith("EventLog.xml")) { SafeXmlDocument safeXmlDocument = new SafeXmlDocument(); safeXmlDocument.Load(Assembly.GetExecutingAssembly().GetManifestResourceStream(text)); Dictionary <string, short> dictionary = new Dictionary <string, short>(); foreach (object obj in safeXmlDocument.SelectNodes("/root/category")) { XmlElement xmlElement = (XmlElement)obj; string attribute = xmlElement.GetAttribute("name"); short value = short.Parse(xmlElement.SelectSingleNode("number").InnerText); dictionary.Add(attribute, value); } foreach (object obj2 in safeXmlDocument.SelectNodes("/root/data")) { XmlElement xmlElement2 = (XmlElement)obj2; string attribute2 = xmlElement2.GetAttribute("name"); uint eventId = (uint)Enum.Parse(typeof(MSExchangeDiagnosticsEventLogConstants.Message), attribute2); string innerText = xmlElement2.SelectSingleNode("category").InnerText; string innerText2 = xmlElement2.SelectSingleNode("stringvalue").InnerText; short categoryId = dictionary[innerText]; string innerText3 = xmlElement2.SelectSingleNode("eventtype").InnerText; string component = string.Empty; XmlNode xmlNode = xmlElement2.SelectSingleNode("component"); if (xmlNode != null) { component = EventLogger.FormatString(xmlNode.InnerText); } string tag = string.Empty; XmlNode xmlNode2 = xmlElement2.SelectSingleNode("tag"); if (xmlNode2 != null) { tag = EventLogger.FormatString(xmlNode2.InnerText); } string exception = string.Empty; XmlNode xmlNode3 = xmlElement2.SelectSingleNode("exception"); if (xmlNode3 != null) { exception = EventLogger.FormatString(xmlNode3.InnerText); } EventLogEntryType enumValue = EventLogger.GetEnumValue <EventLogEntryType>(xmlElement2, "eventtype"); ExEventLog.EventLevel enumValue2 = EventLogger.GetEnumValue <ExEventLog.EventLevel>(xmlElement2, "level"); ExEventLog.EventPeriod enumValue3 = EventLogger.GetEnumValue <ExEventLog.EventPeriod>(xmlElement2, "period"); ExEventLog.EventTuple tuple = new ExEventLog.EventTuple(eventId, categoryId, enumValue, enumValue2, enumValue3); this.tuples.Add(attribute2, new EventLogger.EventData(tuple, component, tag, exception)); string text2 = EventLogger.FormatString(innerText2); if (!TriggerHandler.Triggers.ContainsKey(attribute2)) { TriggerHandler.Triggers.Add(attribute2, new TriggerHandler.TriggerData(innerText3, text2)); } } } } }
private bool CanLogPeriodic(ExEventLog.EventPeriod period, uint eventId, string eventKey, string organizationId) { if (period == ExEventLog.EventPeriod.LogAlways) { return(true); } if (!string.IsNullOrEmpty(organizationId)) { return(this.CanLogPeriodicTenantEvent(eventId, eventKey, organizationId)); } ExEventLog.PeriodicCheckKey key = new ExEventLog.PeriodicCheckKey(eventId, eventKey); DateTime dateTime; bool flag2; lock (this.periodicKeys) { flag2 = this.periodicKeys.TryGetValue(key, out dateTime); } if (!flag2) { lock (this.periodicKeys) { this.periodicKeys[key] = DateTime.UtcNow; } return(true); } if (ExEventLog.EventPeriod.LogOneTime == period) { return(false); } int eventPeriodTime = this.EventSource.EventPeriodTime; if (DateTime.UtcNow >= dateTime.AddSeconds((double)eventPeriodTime)) { lock (this.periodicKeys) { this.periodicKeys.Remove(key); this.periodicKeys[key] = DateTime.UtcNow; } return(true); } return(false); }
public bool LogEvent(string organizationId, uint eventId, short category, ExEventLog.EventLevel level, EventLogEntryType type, ExEventLog.EventPeriod period, string periodicKey, out bool fEventSuppressed, byte[] extraData, params object[] messageArgs) { fEventSuppressed = false; if (messageArgs != null && messageArgs.Length > 32767) { throw new ArgumentException("There were too many strings passed in as messageArgs", "messageArgs"); } if (!this.IsEventCategoryEnabled(category, level)) { return(true); } if (!this.CanLogPeriodic(period, eventId, periodicKey, organizationId)) { fEventSuppressed = true; return(true); } EventInstance instance = new EventInstance((long)((ulong)eventId), (int)category, type); Exception ex = null; try { byte[] array; if (!string.IsNullOrEmpty(organizationId)) { int num = string.IsNullOrEmpty(periodicKey) ? 0 : periodicKey.GetHashCode(); array = Encoding.UTF8.GetBytes(string.Format("<ExchangeEventInfo><OrganizationId>{0}</OrganizationId><PeriodicKey>{1}</PeriodicKey></ExchangeEventInfo>", organizationId, num.ToString("X", CultureInfo.InvariantCulture))); if (extraData != null) { array = array.Concat(extraData).ToArray <byte>(); } } else { array = extraData; } if (messageArgs != null) { for (int i = 0; i < messageArgs.Length; i++) { string text = (messageArgs[i] != null) ? messageArgs[i].ToString() : string.Empty; if (!string.IsNullOrEmpty(text) && text.Length > 31000) { messageArgs[i] = text.Substring(0, 31000) + "..."; } } } this.eventLog.WriteEvent(instance, array, messageArgs); } catch (Win32Exception ex2) { ex = ex2; } catch (InvalidOperationException ex3) { ex = ex3; } catch (AccessViolationException ex4) { ex = ex4; } if (ex != null) { ExTraceGlobals.EventLogTracer.TraceInformation <Exception>(17513, 0L, "WriteEvent returned {0}", ex); return(false); } return(true); }
public EventTuple(uint eventId, short categoryId, EventLogEntryType entryType, ExEventLog.EventLevel level, ExEventLog.EventPeriod period) { this.eventId = eventId; this.categoryId = categoryId; this.entryType = entryType; this.level = level; this.period = period; }