internal static void ParseTracing(ZooKeeperConfiguration config, XElement root) { if (root.Attribute("DefaultTraceLevel") != null) { config.DefaultTraceLevel = ParseSeverity(root.Attribute("DefaultTraceLevel").Value, "Invalid trace level DefaultTraceLevel attribute value on Tracing element for ZooKeeper Client"); } foreach (XElement grandchild in root.Elements()) { if (grandchild == null) { continue; } if (grandchild.Name.LocalName.Equals("TraceLevelOverride") && grandchild.Attribute("TraceLevel") != null && grandchild.Attribute("LogPrefix") != null) { config.TraceLevelOverrides.Add(new Tuple <string, TraceLevel>(grandchild.Attribute("LogPrefix").Value, ParseSeverity(grandchild.Attribute("TraceLevel").Value, "Invalid trace level TraceLevel attribute value on TraceLevelOverride element for ZooKeeper Client prefix " + grandchild.Attribute("LogPrefix").Value))); } } }
/// <summary> /// </summary> public static ZooKeeperConfiguration LoadFromFile(string fileName) { if (fileName == null) { throw new ArgumentNullException("fileName"); } var config = new ZooKeeperConfiguration(); string xml = File.ReadAllText(fileName); XElement root = XDocument.Load(xml).Root; config.LoadFromXml(root); config.SourceFile = fileName; return(config); }
public static void Initialize(ZooKeeperConfiguration config) { if (config == null) { config = new ZooKeeperConfiguration(); } lock (lockable) { if (IsInitialized) { return; // Already initialized } traceLevel = config.DefaultTraceLevel; SetTraceLevelOverrides(config.TraceLevelOverrides); if (!string.IsNullOrEmpty(config.TraceFileName)) { try { logOutputFile = new FileInfo(config.TraceFileName); var l = new LogWriterToFile(logOutputFile); LogConsumers.Add(l); } catch (Exception exc) { Trace.Listeners.Add(new DefaultTraceListener()); Trace.TraceError("Error opening trace file {0} -- Using DefaultTraceListener instead -- Exception={1}", logOutputFile, exc); } } if (Trace.Listeners.Count > 0) { // Plumb in log consumer to write to Trace listeners var traceLogConsumer = new LogWriterToTrace(); LogConsumers.Add(traceLogConsumer); } IsInitialized = true; } }