Skip to content

Instantly share code, notes, and snippets.

Last active May 27, 2022 08:31
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Logging all headers and the body of a request from Azure API Management to Azure Event Hub
<log-to-eventhub logger-id="svenmalvik-logger">
var body = context.Request.Body.As<string>(preserveContent: true);
// ToBase64 to get it better tranfered
var bodyToLog = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(body));
var headers = context.Request.Headers;
Dictionary<string, string> contextProperties = new Dictionary<string, string>();
foreach (var h in headers) {
contextProperties.Add(string.Format("{0}", h.Key), String.Join(", ", h.Value));
var requestLogMessage = new {
Headers = contextProperties,
Body = bodyToLog
return JsonConvert.SerializeObject(requestLogMessage);
<base />
<base />
<base />
<base />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment