Skip to content

Instantly share code, notes, and snippets.

@ThomasArdal
Created October 26, 2017 18:37
Show Gist options
  • Save ThomasArdal/1eefcb064978772eeb6ec3c91e74f8e2 to your computer and use it in GitHub Desktop.
Save ThomasArdal/1eefcb064978772eeb6ec3c91e74f8e2 to your computer and use it in GitHub Desktop.
JSNLog and elmah.io
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddElmahIo("API_KEY", new Guid("LOG_ID"));
var api = ElmahioAPI.Create("API_KEY");
JavascriptLogging.OnLogging += loggingEventArgs =>
{
api.Messages.CreateAndNotify(new Guid("LOG_ID"), new CreateMessage
{
Title = loggingEventArgs.FinalMessage,
Severity = Severity(loggingEventArgs.FinalLevel),
Cookies = loggingEventArgs.LogRequest?.Cookies?.Select(c => new Item {Key = c.Key, Value = c.Value}).ToList(),
ServerVariables = loggingEventArgs.LogRequest?.Headers?.Select(c => new Item { Key = c.Key, Value = c.Value }).ToList(),
QueryString = loggingEventArgs.LogRequest?.QueryParameters?.Select(c => new Item { Key = c.Key, Value = c.Value }).ToList(),
Url = loggingEventArgs.LogRequest?.Url,
Source = loggingEventArgs.LogRequest?.Logger,
Detail = "jeres\nstacktrace\nindsaettes\nher",
});
// Cancel further logging through Microsoft.Extensions.Logging, since we already logged the message
loggingEventArgs.Cancel = true;
};
app.UseJSNLog(new LoggingAdapter(loggerFactory));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment