/// <summary> /// Create a manifest file for each EventSource in 'managedDll'. and registers (or unregisters) /// those manifests with the system. /// </summary> private static List <Tuple <string, string> > RegisterManagedDll(string managedDllPath, bool unregister, string manifestPrefix = null) { if (manifestPrefix == null) { manifestPrefix = Path.ChangeExtension(managedDllPath, null); } bool bErrors = false; List <Tuple <string, string> > ret = new List <Tuple <string, string> >(); foreach (var eventSource in GetEventSources(managedDllPath)) { try { string providerName = EventSourceReflectionProxy.GetName(eventSource); string manifestXmlPath = manifestPrefix + "." + providerName + ".etwManifest.man"; string manifestDllPath = manifestPrefix + "." + providerName + ".etwManifest.dll"; CreateManifest(eventSource, manifestDllPath, manifestXmlPath); if (!File.Exists(manifestXmlPath)) { continue; } CompileManifest(manifestXmlPath, manifestDllPath); RegisterManifestDll(manifestXmlPath, manifestDllPath, unregister); ret.Add(Tuple.Create(manifestXmlPath, manifestDllPath)); } catch (MultiErrorException e) { bErrors = true; Console.Error.WriteLine("Error: " + eventSource.FullName + ": " + e.Message); foreach (var error in e.Errors) { Console.Error.WriteLine("Error: " + eventSource.FullName + ": " + error); } } catch (ApplicationException e) { bErrors = true; Console.Error.WriteLine("Error: " + eventSource.FullName + ": " + e.Message); } } if (bErrors) { throw new ApplicationException("Failures encountered during " + (unregister ? "unregistration" : "registration") + " of EventSources in " + managedDllPath); } return(ret); }
/// <summary> /// Given an eventSourceType, and the name of the DLL that the manifest where the manifest /// is intended to be placed, create the manifest XML and put it in the file manifestXmlPath /// </summary> private static void CreateManifest(Type eventSourceType, string manifestDllPath, string manifestXmlPath, bool bForce = true) { try { string providerXML = (string)EventSourceReflectionProxy.GenerateManifest(eventSourceType, Path.GetFullPath(manifestDllPath), bForce); if (!string.IsNullOrEmpty(providerXML)) { using (TextWriter writer = File.CreateText(manifestXmlPath)) { writer.Write(providerXML); } } } catch (TargetInvocationException e) { string msg = e.InnerException != null ? e.InnerException.Message : e.Message; throw new MultiErrorException("Generation of ETW manifest failed", msg); } }