@@ -221,9 +221,26 @@ public static void ReadStackifyJSONConfig()
221221 {
222222 try
223223 {
224+ var ASPEnvironment = System . Environment . GetEnvironmentVariable ( "ASPNETCORE_ENVIRONMENT" ) ;
225+ var DotnetEnvironment = System . Environment . GetEnvironmentVariable ( "DOTNET_ENVIRONMENT" ) ;
224226 string baseDirectory = Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) ;
225- string jsonPath = Path . Combine ( baseDirectory , "Stackify.json" ) ;
226- string json ;
227+ string jsonPath = string . Empty ;
228+ string json = string . Empty ;
229+
230+ ASPEnvironment = "Production" ;
231+
232+ if ( ! String . IsNullOrEmpty ( ASPEnvironment ) )
233+ {
234+ jsonPath = Path . Combine ( baseDirectory , $ "Stackify.{ ASPEnvironment } .json") ;
235+ }
236+ else if ( ! String . IsNullOrEmpty ( DotnetEnvironment ) )
237+ {
238+ jsonPath = Path . Combine ( baseDirectory , $ "Stackify.{ DotnetEnvironment } .json") ;
239+ }
240+ else
241+ {
242+ jsonPath = Path . Combine ( baseDirectory , "Stackify.json" ) ;
243+ }
227244
228245 if ( File . Exists ( jsonPath ) )
229246 {
@@ -241,7 +258,20 @@ public static void ReadStackifyJSONConfig()
241258 else
242259 {
243260 string iisBaseDirectory = System . Web . Hosting . HostingEnvironment . ApplicationPhysicalPath ;
244- string iisJsonPath = Path . Combine ( iisBaseDirectory , "Stackify.json" ) ;
261+ string iisJsonPath = string . Empty ;
262+
263+ if ( ! String . IsNullOrEmpty ( ASPEnvironment ) )
264+ {
265+ iisJsonPath = Path . Combine ( iisBaseDirectory , $ "Stackify.{ ASPEnvironment } .json") ;
266+ }
267+ else if ( ! String . IsNullOrEmpty ( DotnetEnvironment ) )
268+ {
269+ iisJsonPath = Path . Combine ( iisBaseDirectory , $ "Stackify.{ DotnetEnvironment } .json") ;
270+ }
271+ else
272+ {
273+ iisJsonPath = Path . Combine ( iisBaseDirectory , "Stackify.json" ) ;
274+ }
245275
246276 if ( File . Exists ( iisJsonPath ) )
247277 {
@@ -295,7 +325,7 @@ public static void ReadStackifyJSONConfig(string filePath)
295325 public static void SetStackifyObj ( JObject obj )
296326 {
297327 AppName = TryGetValue ( obj , "AppName" ) ?? AppName ;
298- Environment = GetEnvironment ( obj ) ;
328+ Environment = TryGetValue ( obj , "Environment" ) ?? Environment ;
299329 ApiKey = TryGetValue ( obj , "ApiKey" ) ?? ApiKey ;
300330 }
301331
@@ -327,26 +357,5 @@ private static string TryGetValue(JToken jToken, string key)
327357
328358 return r ;
329359 }
330- public static string GetEnvironment ( JObject envName = null )
331- {
332- var ASPEnvironment = System . Environment . GetEnvironmentVariable ( "ASPNETCORE_ENVIRONMENT" ) ;
333- var DotnetEnvironment = System . Environment . GetEnvironmentVariable ( "DOTNET_ENVIRONMENT" ) ;
334-
335- if ( ! String . IsNullOrEmpty ( ASPEnvironment ) )
336- {
337- return ASPEnvironment ;
338- }
339- else if ( ! String . IsNullOrEmpty ( DotnetEnvironment ) )
340- {
341- return DotnetEnvironment ;
342- }
343- else
344- {
345- var environmentName = TryGetValue ( envName , "Environment" ) ?? Environment ;
346-
347- return environmentName ;
348- }
349-
350- }
351360 }
352361}
0 commit comments