public void DisableLoggingTest() { string testFilePath = "test-disable-all.config"; try { //Write tempXml content to a new file named test.config WriteToXmlFile(testFilePath, tempXml); LogConfigOption logConfigOption = new LogConfigOption(); logConfigOption.Logging = "Disable"; LogHelper.SetLoggingConfig(logConfigOption, testFilePath, "Test"); XmlDocument doc = new XmlDocument(); doc.Load(testFilePath); Console.WriteLine($"Current config file content is: ${doc.InnerXml}"); var targetNodes = doc.GetElementsByTagName("add").Cast <XmlNode>() .Where(item => item.Attributes["key"].Value.Contains("serilog:write-to")).ToList(); Assert.AreEqual(0, targetNodes.Count); } catch (Exception e) { Console.WriteLine(e); throw; } finally { if (File.Exists(testFilePath)) { File.Delete(testFilePath); Console.WriteLine($"{testFilePath} is deleted"); } } }
public void SetAzureAnalyticsLoggingTest() { string testFilePath = "test-AzureAnalytics-logging.config"; try { //Write tempXml content to a new file named test.config WriteToXmlFile(testFilePath, tempXml); LogConfigOption logConfigOption = new LogConfigOption(); logConfigOption.Logging = "Enable"; logConfigOption.AzureAnalyticsLogging = true; logConfigOption.AzureAnalyticsWorkspaceId = "workspaceId"; logConfigOption.AzureAnalyticsAuthenticationId = "authenticationId"; logConfigOption.AzureAnalyticsLoggingLevel = "Verbose"; LogHelper.SetLoggingConfig(logConfigOption, testFilePath, "Test"); XmlDocument doc = new XmlDocument(); doc.Load(testFilePath); Console.WriteLine($"Current config file content is: ${doc.InnerXml}"); var usingAzureAnalyticsNodes = doc.GetElementsByTagName("add").Cast <XmlNode>() .Where(item => item.Attributes["key"].Value.Equals("serilog:using:AzureLogAnalytics")).ToList(); var loggingLevelNodes = doc.GetElementsByTagName("add").Cast <XmlNode>() .Where(item => item.Attributes["key"].Value.Equals("serilog:write-to:AzureLogAnalytics.restrictedToMinimumLevel")).ToList(); var workspaceIdNodes = doc.GetElementsByTagName("add").Cast <XmlNode>() .Where(item => item.Attributes["key"].Value.Equals("serilog:write-to:AzureLogAnalytics.workspaceId")).ToList(); var authenticationIdNodes = doc.GetElementsByTagName("add").Cast <XmlNode>() .Where(item => item.Attributes["key"].Value.Equals("serilog:write-to:AzureLogAnalytics.authenticationId")).ToList(); Assert.AreEqual(1, usingAzureAnalyticsNodes.Count); Assert.AreEqual("Serilog.Sinks.AzureAnalytics", usingAzureAnalyticsNodes[0].Attributes["value"].Value); Assert.AreEqual(1, loggingLevelNodes.Count); Assert.AreEqual("Verbose", loggingLevelNodes[0].Attributes["value"].Value); Assert.AreEqual(1, workspaceIdNodes.Count); Assert.AreEqual("workspaceId", workspaceIdNodes[0].Attributes["value"].Value); Assert.AreEqual(1, authenticationIdNodes.Count); Assert.AreEqual("authenticationId", authenticationIdNodes[0].Attributes["value"].Value); } catch (Exception e) { Console.WriteLine(e); throw; } finally { if (File.Exists(testFilePath)) { File.Delete(testFilePath); Console.WriteLine($"{testFilePath} is deleted"); } } }