public void Sample() { var client = ClientHelper.GetSdkClient(); LogEventManager.Verbose("This is a verbose message."); LogEventManager.Debug("This is a debug message."); LogEventManager.Info("This is a info message."); LogEventManager.Warn("This is a info message."); LogEventManager.Error("This is an error message.", new Sdk.Common.MetrikException("This is an ERROR exception test.")); LogEventManager.Fatal("This is a fatal message", new Sdk.Common.MetrikException("This is a FATAL exception test.")); // This is for checking if the logs are populated properly for each event type Assert.IsTrue(true); }
public static void OutputCurlCommand(HttpClient client, HttpMethod method, string url, StringContent content, bool writeAllHeaders = false) { if (GlobalEvents.IsListening(LogLevelType.Debug)) { var sbCurl = new StringBuilder("CURL equivalent command: " + Environment.NewLine); sbCurl.Append("curl "); if (method == HttpMethod.Get) { sbCurl.AppendLine(@"-X GET \"); } else if (method == HttpMethod.Delete) { sbCurl.AppendLine(@"-X DELETE \"); } else if (method == HttpMethod.Post) { sbCurl.AppendLine(@"-X POST \"); } else if (method == HttpMethod.Put) { sbCurl.AppendLine(@"-X PUT \"); } if (content != null) { sbCurl.AppendFormat("\t-H \"Content-Type: {0}\" \\{1}", content.Headers.ContentType.MediaType, Environment.NewLine); } foreach (var header in client.DefaultRequestHeaders) { bool writeHeader = true; // if (writeAllHeaders) // { // writeHeader = true; // } // else if (header.Key.StartsWith("x-", StringComparison.OrdinalIgnoreCase) || header.Key.StartsWith("Authorization")) // { // writeHeader = true; // } if (writeHeader) { sbCurl.AppendFormat("\t-H \"{0}: {1}\" \\{2}", header.Key, header.Value.Aggregate((i, j) => i + " " + j), Environment.NewLine); } } if (content != null) { string jsonData = string.Empty; Task task = content.ReadAsStringAsync().ContinueWith(async f => { jsonData = f.Result; }); task.Wait(); if (!string.IsNullOrWhiteSpace(jsonData)) { sbCurl.AppendFormat("\t-d \'{0}\' \\ {1}", jsonData.Replace(Environment.NewLine, Environment.NewLine + "\t\t"), Environment.NewLine); } } sbCurl.AppendLine(url); LogEventManager.Debug(sbCurl.ToString()); } }