Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            IServiceContainer services = new ServiceContainer();

            services.AddType <IInternalLogger, ConsoleLogger>();

            Action <ComponentOptions> componentOptions = component =>
            {
                component.AddLineProtocolCollector(options =>
                {
                    options.Server   = "http://localhost:8186";
                    options.Database = "aspectcore_apm";
                });
                component.AddApplicationProfiler(op => op.Interval = 1);
            };

            Action <ApplicationOptions> applicationOptions = options =>
            {
                options.ApplicationName = typeof(Program).Assembly.GetName().Name;
                options.Environment     = "Development";
            };

            services.AddAspectCoreAPM(componentOptions, applicationOptions);

            var serviceResolver = services.Build();

            var collectorLifetime = serviceResolver.Resolve <IComponentLifetime>();

            collectorLifetime.Start();

            Console.ReadKey();

            collectorLifetime.Stop();
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            IServiceContainer services = new ServiceContainer();

            Action <ApplicationOptions> appOptions = options =>
            {
                options.ApplicationName = "AspectCoreAPMDemo";   //配置应用名称,一定要有
                options.Environment     = "Development";         //配置应用环境,一定要有
            };

            services.AddAspectCoreAPM(compontent =>
            {
                compontent.AddApplicationProfiler();
                compontent.AddHttpProfiler();
                compontent.AddLineProtocolCollector(options =>
                {
                    options.Database = "aspectcore";
                    options.Server   = "http://192.168.3.4:8086";
                });
            }, appOptions);

            ContainerBuilder containerBuilder = new ContainerBuilder();

            containerBuilder.Populate(services);

            DependencyResolver.SetResolver(new AutofacDependencyResolver(containerBuilder.Build()));

            var lifetime = DependencyResolver.Current.GetService <IComponentLifetime>();

            lifetime.Start();  //启动AspectCoreAPM
        }