Created
October 26, 2017 18:37
-
-
Save ThomasArdal/1eefcb064978772eeb6ec3c91e74f8e2 to your computer and use it in GitHub Desktop.
JSNLog and elmah.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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