From 1ade0096f3815edfed17bc7dfc796950b5cfd709 Mon Sep 17 00:00:00 2001 From: James Schafer Date: Sun, 11 Jun 2017 20:43:59 -0400 Subject: [PATCH] Added Feature to adjust the TraceLevel based on Environment Variable. --- Melody49Notifier/Melody49Notifier.cs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/Melody49Notifier/Melody49Notifier.cs b/Melody49Notifier/Melody49Notifier.cs index c7d1f0e..0ee2941 100644 --- a/Melody49Notifier/Melody49Notifier.cs +++ b/Melody49Notifier/Melody49Notifier.cs @@ -9,10 +9,11 @@ namespace Melody49Notifier { public static class Melody49Notifier { - [FunctionName("Melody49Notifier")] - public static void Run([TimerTrigger("0 0 8-18 * * FRI")]TimerInfo myTimer, TraceWriter log) + public static void Run([TimerTrigger("0/10 * * * * * ")]TimerInfo myTimer, TraceWriter log) //[TimerTrigger("0 0 8-18 * * FRI")]TimerInfo myTimer, TraceWriter log) { + SetTraceLevel(log); + log.Info($"C# Timer trigger function started at: {DateTime.Now}."); ICurrentTheaterScheduleDataFileManager currentTheaterScheduleDataFileManager = new CurrentTheaterScheduleDataFileManager(log); @@ -32,7 +33,27 @@ public static void Run([TimerTrigger("0 0 8-18 * * FRI")]TimerInfo myTimer, Trac log.Info($"C# Timer trigger function completed at: {DateTime.Now}."); } - private static bool TheaterScheduleHasUpdated(TraceWriter log, ICurrentTheaterScheduleDataFileManager currentTheaterScheduleDataFileManager, out TheaterSchedule currentTheaterSchedule) + private static void SetTraceLevel(TraceWriter log) + { + switch (Environment.GetEnvironmentVariable("TraceLevel")?.ToLower()) + { + case "error": + log.Level = System.Diagnostics.TraceLevel.Error; + break; + case "warning": + log.Level = System.Diagnostics.TraceLevel.Warning; + break; + case "verbose": + log.Level = System.Diagnostics.TraceLevel.Verbose; + break; + case "info": + default: + log.Level = System.Diagnostics.TraceLevel.Info; + break; + } + } + + private static bool TheaterScheduleHasUpdated(TraceWriter log, ICurrentTheaterScheduleDataFileManager currentTheaterScheduleDataFileManager, out TheaterSchedule currentTheaterSchedule) { ICurrentTheaterScheduleWebRequestManager currentTheaterScheduleWebRequestManager = new CurrentTheaterScheduleWebRequestManager(log, new TheaterScheduleHTMLParser(log)); ITheaterScheduleComparer theaterScheduleComparer = new TheaterScheduleComparer(log);