Alternatively, you can simply implement the REST POST function in the .Net controller, call it via AJAX in your JavaScript code.
Example:
.Net Controller Funktion
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // POST: LogFromJavaScript [AllowAnonymous] [HttpPost] [ValidateInput(false)] public void LogFromJavaScript(String errorMessage) { log.Error("Log from JavaScript: " + errorMessage); }
Java Script AJAX Implementation
function LogFromJavaScript(errorMessage) { $.ajax( { url: window.urlLogError, type: "POST", dataType: "text", cache: false, data: { errorMessage: errorMessage } }); }
And then use it in your JavaScript code
window.LogFromJavaScript("Hello JS Log!");
source share