Skip to content

Commit 63e92f0

Browse files
author
Michael Mantos
committed
Add read stackify json config on load settings
1 parent eea2221 commit 63e92f0

File tree

6 files changed

+21
-13
lines changed

6 files changed

+21
-13
lines changed

Src/FullFrameworkWebApp/Controllers/HomeController.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public ActionResult Index()
3939
Debug.WriteLine($"ApiKey: {StackifyLib.Config.ApiKey}");
4040

4141
ViewBag.JsonPath = jsonPath;
42+
ViewBag.AppName = StackifyLib.Config.AppName;
43+
ViewBag.Environment = StackifyLib.Config.Environment;
44+
ViewBag.ApiKey = StackifyLib.Config.ApiKey;
4245
return View();
4346
}
4447

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"AppName": "FullFrameworkWebAppTest",
3-
"Environment": "Testing",
4-
"ApiKey": "6Wr6Sp5Nq9Ok0Ga6Jc3Gz6Vm2Bh7Zp9Em4Of4Kb"
2+
"AppName": "FullFrameworkWebAppTestJson",
3+
"Environment": "TestingJson",
4+
"ApiKey": ""
55
}

Src/FullFrameworkWebApp/Views/Home/Index.cshtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@
2828
<p>You can easily find a web hosting company that offers the right mix of features and price for your applications.</p>
2929
<p><a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkId=301867">Learn more &raquo;</a></p>
3030
</div>
31+
<h3>@ViewBag.AppName</h3>
32+
<h3>@ViewBag.Environment</h3>
33+
<h3>@ViewBag.ApiKey</h3>
3134
</div>

Src/StackifyLib/Config.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public static void LoadSettings()
3636
{
3737
try
3838
{
39+
if (IsStackifyJsonLoaded == false) {
40+
ReadStackifyJSONConfig(); // TODO: Better way?
41+
}
42+
3943
CaptureServerVariables = Get("Stackify.CaptureServerVariables", bool.FalseString).Equals(bool.TrueString, StringComparison.CurrentCultureIgnoreCase);
4044

4145
CaptureSessionVariables = Get("Stackify.CaptureSessionVariables", bool.FalseString).Equals(bool.TrueString, StringComparison.CurrentCultureIgnoreCase);
@@ -155,6 +159,8 @@ public static void LoadSettings()
155159

156160
public static int LoggingJsonMaxFields { get; set; } = 50;
157161

162+
public static bool? IsStackifyJsonLoaded { get; set; } = false;
163+
158164

159165
/// <summary>
160166
/// Attempts to fetch a setting value given the key.
@@ -221,16 +227,13 @@ public static void ReadStackifyJSONConfig()
221227

222228
if (File.Exists(jsonPath))
223229
{
224-
StackifyAPILogger.Log($"#jsonPath exists: {jsonPath}");
225-
226230
using (var fs = new FileStream(jsonPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
227231
{
228232
using (var sr = new StreamReader(fs))
229233
{
230234
json = sr.ReadToEnd();
231235
}
232236
}
233-
234237
var obj = JObject.Parse(json, Settings);
235238
Config.SetStackifyObj(obj);
236239
}
@@ -242,7 +245,6 @@ public static void ReadStackifyJSONConfig()
242245

243246
if (File.Exists(iisJsonPath))
244247
{
245-
StackifyAPILogger.Log($"#iisJsonPath exists: {iisJsonPath}");
246248
using (var fs = new FileStream(iisJsonPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
247249
{
248250
using (var sr = new StreamReader(fs))
@@ -261,7 +263,7 @@ public static void ReadStackifyJSONConfig()
261263
{
262264
StackifyAPILogger.Log("#Config #ReadStackifyJSONConfig failed", ex);
263265
}
264-
266+
IsStackifyJsonLoaded = true;
265267
}
266268

267269
#if JSONTEST

samples/CoreWebApp/Stackify.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"AppName": "CoreWebApp_stackifyjson",
33
"Environment": "Dev_stackifyjson",
4-
"ApiKey": "sampleKey_stackifyjson"
4+
"ApiKey": ""
55
}

samples/CoreWebApp/Startup.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public Startup(IHostingEnvironment env)
3131

3232
var builder = new ConfigurationBuilder()
3333
.SetBasePath(env.ContentRootPath)
34-
.AddJsonFile("Stackify.json", optional: true, reloadOnChange: true)
35-
.AddJsonFile($"Stackify.{env.EnvironmentName}.json", optional: true)
34+
//.AddJsonFile("Stackify.json", optional: true, reloadOnChange: true)
35+
//.AddJsonFile($"Stackify.{env.EnvironmentName}.json", optional: true)
3636
.AddEnvironmentVariables();
3737
Configuration = builder.Build();
38-
Configuration.ConfigureStackifyLogging();
38+
//Configuration.ConfigureStackifyLogging();
3939

4040
//StackifyLib.Config.Environment = env.EnvironmentName;
4141

@@ -87,7 +87,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
8787
// var path = Path.Combine(Directory.GetCurrentDirectory(), "nlog.config");
8888
// NLog.LogManager.Configuration = new XmlLoggingConfiguration(path, true);
8989
// app.AddNLogWeb();
90-
//app.ConfigureStackifyLogging(Configuration);
90+
app.ConfigureStackifyLogging(Configuration);
9191

9292
app.UseMvc();
9393
}

0 commit comments

Comments
 (0)