Det er nå {{messages.length}} meldinger (av {{totalRecieved}}).
Usage
//Javascript
function remoteLog(msg) {
$.ajax({
url: "http://log.testmaskin.com/home/Log",
data: { message: msg },
dataType: "jsonp"
});
window.console && console.log(msg);
}
//c#
public static class Logger
{
public static HttpClient client = new HttpClient();
public static string GetJson(this object o)
{
try
{
var serializer = new JsonSerializer
{
NullValueHandling = NullValueHandling.Ignore,
Formatting = Formatting.Indented,
ObjectCreationHandling = ObjectCreationHandling.Replace,
MissingMemberHandling = MissingMemberHandling.Ignore,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
DateFormatHandling = 0,
DateFormatString = "dd.MM.yyyy"
};
using (var sw = new StringWriter())
using (var writer = new JsonTextWriter(sw))
{
serializer.Serialize(writer, o);
return sw.ToString();
}
}
catch (Exception err)
{
return "{ \"msg\" : \"" + err.Message + "\n" + err.StackTrace.Replace("\\", "\\\\") + "\"}";
}
}
public static void Log(this object msg)
{
var m = new StringContent(new { message = msg.GetJson() }.GetJson(), Encoding.UTF8, "application/json");
client.PostAsync("http://log.testmaskin.com/home/log", m);
}
}
Logger.Log(new {msg="Hello world!"});