示例#1
0
        public bool Execute()
        {
            InstrumentAttribute assemblyAttribute = null;

            if (this.AutomaticInstrumentationScopes != InstrumentationScopes.None)
            {
                assemblyAttribute = new InstrumentAttribute()
                {
                    Scopes = this.AutomaticInstrumentationScopes
                };
                assemblyAttribute.IncludeCompilerGeneratedCode = this.IncludeCompilerGeneratedCode;
            }

            var targets = new List <InstrumentationTarget>();

            foreach (string assyPath in this.InputPaths)
            {
                InstrumentationDiscovererBase discoverer = null;

                if (this.UseReflectionBasedDiscovery)
                {
                    _logger.Info("Using legacy reflection-based discovery on request");
                    discoverer = new ReflectedInstrumentationDiscoverer();
                }
                else
                {
                    discoverer = new CciInstrumentationDiscoverer();
                }

                targets.AddRange(discoverer.GetInstrumentationSet(assyPath, assemblyAttribute, x => true));
            }

            _logger.Info(string.Format("Processed {0} targets", targets.Count));

            if (targets.Count > MAX_TARGETS_BEFORE_WARNING)
            {
                _logger.Warn(string.Format("WARNING - New Relic recommend instrumenting no more than {0} targets to avoid performance issues.", MAX_TARGETS_BEFORE_WARNING));
                _logger.Warn(string.Format("See https://newrelic.com/docs/dotnet/CustomInstrumentation.html for more information"));
            }

            string tempPath = Path.GetTempFileName();

            using (FileStream w = new FileStream(tempPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
            {
                Renderer.RenderToStream(targets, w);
            }

            // Delete existing file, if required
            if (File.Exists(this.OutputPath))
            {
                File.Delete(this.OutputPath);
            }

            File.Move(tempPath, this.OutputPath);

            return(true);
        }
 public void Initialise()
 {
     _discoverer = this.GetDiscoverer();
 }