diff --git a/src/SkyApm.Agent.Hosting/Extensions/ServiceCollectionExtensions.cs b/src/SkyApm.Agent.Hosting/Extensions/ServiceCollectionExtensions.cs index c722f664..2e8346f3 100644 --- a/src/SkyApm.Agent.Hosting/Extensions/ServiceCollectionExtensions.cs +++ b/src/SkyApm.Agent.Hosting/Extensions/ServiceCollectionExtensions.cs @@ -48,8 +48,6 @@ public static class ServiceCollectionExtensions public static IServiceCollection AddSkyAPM(this IServiceCollection services, Action extensionsSetup = null) { - #region can be optimized - string environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); if (environment == null || environment.Length < 1) { @@ -60,6 +58,16 @@ public static IServiceCollection AddSkyAPM(this IServiceCollection services, configurationBuilder.AddJsonFile("skyapm.json", true); configurationBuilder.AddJsonFile("skyapm." + environment + ".json", true); IConfiguration configuration = configurationBuilder.Build(); + + services.AddSkyAPM(configuration,extensionsSetup); + return services; + } + + public static IServiceCollection AddSkyAPM(this IServiceCollection services, IConfiguration configuration, + Action extensionsSetup = null) + { + #region can be optimized + string enable = configuration?.GetSection("SkyWalking:Enable").Value; if (enable != null && "false".Equals(enable.ToLower())) {