public void Trace_AppliesLevelFilter() { DirectoryInfo directory = new DirectoryInfo(_logFilePath); directory.Create(); int count = directory.EnumerateFiles().Count(); Assert.Equal(0, count); FileTraceWriter traceWriter = new FileTraceWriter(_logFilePath, TraceLevel.Info); traceWriter.Verbose("Test Verbose"); traceWriter.Info("Test Info"); traceWriter.Warning("Test Warning"); traceWriter.Error("Test Error"); traceWriter.Flush(); string logFile = directory.EnumerateFiles().First().FullName; string text = File.ReadAllText(logFile); Assert.True(text.Contains("Test Error")); Assert.True(text.Contains("Test Warning")); Assert.True(text.Contains("Test Info")); Assert.False(text.Contains("Test Verbose")); }
public void Trace_WritesExpectedLogs() { DirectoryInfo directory = new DirectoryInfo(_logFilePath); directory.Create(); int count = directory.EnumerateFiles().Count(); Assert.Equal(0, count); FileTraceWriter traceWriter = new FileTraceWriter(_logFilePath, TraceLevel.Info); traceWriter.Verbose("Test Verbose"); traceWriter.Info("Test Info"); traceWriter.Warning("Test Warning"); traceWriter.Error("Test Error"); // trace a system event - expect it to be ignored var properties = new Dictionary <string, object> { { ScriptConstants.TracePropertyIsSystemTraceKey, true } }; traceWriter.Info("Test System", properties); traceWriter.Flush(); string logFile = directory.EnumerateFiles().First().FullName; string text = File.ReadAllText(logFile); Assert.True(text.Contains("Test Error")); Assert.True(text.Contains("Test Warning")); Assert.True(text.Contains("Test Info")); Assert.False(text.Contains("Test Verbose")); Assert.False(text.Contains("Test System")); }
public static void WarmUp(WebHostSettings settings) { var traceWriter = new FileTraceWriter(Path.Combine(settings.LogPath, "Host"), TraceLevel.Info); ScriptHost host = null; try { traceWriter.Info("Warm up started"); string rootPath = settings.ScriptPath; if (Directory.Exists(rootPath)) { Directory.Delete(rootPath, true); } Directory.CreateDirectory(rootPath); string content = ReadResourceString("Functions.host.json"); File.WriteAllText(Path.Combine(rootPath, "host.json"), content); // read in the C# function string functionPath = Path.Combine(rootPath, "Test-CSharp"); Directory.CreateDirectory(functionPath); content = ReadResourceString("Functions.Test_CSharp.function.json"); File.WriteAllText(Path.Combine(functionPath, "function.json"), content); content = ReadResourceString("Functions.Test_CSharp.run.csx"); File.WriteAllText(Path.Combine(functionPath, "run.csx"), content); // read in the F# function functionPath = Path.Combine(rootPath, "Test-FSharp"); Directory.CreateDirectory(functionPath); content = ReadResourceString("Functions.Test_FSharp.function.json"); File.WriteAllText(Path.Combine(functionPath, "function.json"), content); content = ReadResourceString("Functions.Test_FSharp.run.fsx"); File.WriteAllText(Path.Combine(functionPath, "run.fsx"), content); traceWriter.Info("Warm up functions deployed"); ScriptHostConfiguration config = new ScriptHostConfiguration { RootScriptPath = rootPath, FileLoggingMode = FileLoggingMode.Never, RootLogPath = settings.LogPath, TraceWriter = traceWriter, FileWatchingEnabled = false }; config.HostConfig.StorageConnectionString = null; config.HostConfig.DashboardConnectionString = null; host = ScriptHost.Create(ScriptSettingsManager.Instance, config); traceWriter.Info(string.Format("Starting Host (Id={0})", host.ScriptConfig.HostConfig.HostId)); host.Start(); var arguments = new Dictionary<string, object> { { "input", "{}" } }; host.CallAsync("Test-CSharp", arguments).Wait(); host.CallAsync("Test-FSharp", arguments).Wait(); host.Stop(); traceWriter.Info("Warm up succeeded"); } catch (Exception ex) { traceWriter.Error(string.Format("Warm up failed: {0}", ex)); } finally { host?.Dispose(); traceWriter.Dispose(); } }
public void Trace_WritesExpectedLogs() { DirectoryInfo directory = new DirectoryInfo(_logFilePath); directory.Create(); int count = directory.EnumerateFiles().Count(); Assert.Equal(0, count); FileTraceWriter traceWriter = new FileTraceWriter(_logFilePath, TraceLevel.Info); traceWriter.Verbose("Test Verbose"); traceWriter.Info("Test Info"); traceWriter.Warning("Test Warning"); traceWriter.Error("Test Error"); // trace a system event - expect it to be ignored var properties = new Dictionary<string, object> { { ScriptConstants.TracePropertyIsSystemTraceKey, true } }; traceWriter.Info("Test System", properties); traceWriter.Flush(); string logFile = directory.EnumerateFiles().First().FullName; string text = File.ReadAllText(logFile); Assert.True(text.Contains("Test Error")); Assert.True(text.Contains("Test Warning")); Assert.True(text.Contains("Test Info")); Assert.False(text.Contains("Test Verbose")); Assert.False(text.Contains("Test System")); }
public static void WarmUp(WebHostSettings settings) { var traceWriter = new FileTraceWriter(Path.Combine(settings.LogPath, "Host"), TraceLevel.Info); ScriptHost host = null; try { traceWriter.Info("Warm up started"); string rootPath = settings.ScriptPath; if (Directory.Exists(rootPath)) { Directory.Delete(rootPath, true); } Directory.CreateDirectory(rootPath); string content = ReadResourceString("Functions.host.json"); File.WriteAllText(Path.Combine(rootPath, "host.json"), content); // read in the C# function string functionPath = Path.Combine(rootPath, "Test-CSharp"); Directory.CreateDirectory(functionPath); content = ReadResourceString("Functions.Test_CSharp.function.json"); File.WriteAllText(Path.Combine(functionPath, "function.json"), content); content = ReadResourceString("Functions.Test_CSharp.run.csx"); File.WriteAllText(Path.Combine(functionPath, "run.csx"), content); // read in the F# function functionPath = Path.Combine(rootPath, "Test-FSharp"); Directory.CreateDirectory(functionPath); content = ReadResourceString("Functions.Test_FSharp.function.json"); File.WriteAllText(Path.Combine(functionPath, "function.json"), content); content = ReadResourceString("Functions.Test_FSharp.run.fsx"); File.WriteAllText(Path.Combine(functionPath, "run.fsx"), content); traceWriter.Info("Warm up functions deployed"); ScriptHostConfiguration config = new ScriptHostConfiguration { RootScriptPath = rootPath, FileLoggingMode = FileLoggingMode.Never, RootLogPath = settings.LogPath, TraceWriter = traceWriter, FileWatchingEnabled = false }; config.HostConfig.StorageConnectionString = null; config.HostConfig.DashboardConnectionString = null; host = ScriptHost.Create(config); traceWriter.Info(string.Format("Starting Host (Id={0})", host.ScriptConfig.HostConfig.HostId)); host.Start(); var arguments = new Dictionary <string, object> { { "input", "{}" } }; host.CallAsync("Test-CSharp", arguments).Wait(); host.CallAsync("Test-FSharp", arguments).Wait(); host.Stop(); traceWriter.Info("Warm up succeeded"); } catch (Exception ex) { traceWriter.Error(string.Format("Warm up failed: {0}", ex)); } finally { host?.Dispose(); traceWriter.Dispose(); } }