ErrLog.IO supports manual submission of errors via a Webhook. This can be used
from a variety of languages, with example usage below.
To use this API, simply create a JSON object and send it via a POST to our our
Webhook endpoint.
All objects (apart from your apikey) are dynamically typed, meaning you can
include objects of any type, and from any language or platform, without having to specifically
provide a strongly typed value.
Webhook Endpoint:
https://relay.errlog.io/api/v1/log
Note: In the example below we've
used Newtonsoft.Json to serialize an object into a JSON string.
try {
Console.WriteLine("We're going to throw an exception.");
string result = null;
string upper = result.ToUpper();
} catch (Exception ex) {
StackTrace st = new StackTrace(ex, true);
var obj = new {
message = "This is a test message",
apikey = "[Your-api-key]",
applicationname = "Test Application",
type = ex.GetType().ToString(),
environment = Environment.GetEnvironmentVariables(),
errordate = DateTime.Now,
trace = ex.StackTrace,
filename = st.GetFrame(0).GetFileName(),
method = st.GetFrame(0).GetMethod().Name,
lineno = st.GetFrame(0).GetFileLineNumber(),
colno = st.GetFrame(0).GetFileColumnNumber(),
};
StringContent content = new StringContent(JsonConvert.SerializeObject(obj),
Encoding.UTF8, "application/json");
HttpClient client = new HttpClient();
// You can capture the response if you are expecting a result.
// Most of the time this will be "OK" but could also be "Missing API Key", etc.
string apiUrl = "https://relay.errlog.io/api/v1/log";
HttpContent response = client.PostAsync(apiUrl, content).Result.Content;
string result = response.ReadAsStringAsync().Result;
}
Note: In the example below we've
used Newtonsoft.Json to serialize an object into a JSON string.
Try
Console.WriteLine("We're going to throw an exceptiont.")
Dim result As String = Nothing
Dim upper As String = result.ToUpper()
Catch ex As Exception
Dim st As New StackTrace(ex, True)
Dim obj = New With { _
Key .message = "This is a test message", _
Key .apikey = "[Your-api-key]", _
Key .applicationname = "Test Application", _
Key .type = ex.[GetType]().ToString(), _
Key .environment = Environment.GetEnvironmentVariables(), _
Key .errordate = DateTime.Now, _
Key .trace = ex.StackTrace, _
Key .filename = st.GetFrame(0).GetFileName(), _
Key .method = st.GetFrame(0).GetMethod().Name, _
Key .lineno = st.GetFrame(0).GetFileLineNumber(), _
Key .colno = st.GetFrame(0).GetFileColumnNumber() _
}
Dim content As New StringContent(JsonConvert.SerializeObject(obj), Encoding.UTF8, "application/json")
Dim client As New HttpClient()
' You can capture the response if you are expecting a result.
' Most of the time this will be "OK" but could also be "Missing API Key", etc.
Dim apiUrl as string = "https://relay.errlog.io/api/v1/log";
Dim response As HttpContent = client.PostAsync(apiUrl, content).Result.Content
Dim result As String = response.ReadAsStringAsync().Result
End Try
curl -H "Content-Type: application/json" http://relay.errlog.io/api/v1/log
-d '{ "message": "This is a test message from a Sample Project",
"apikey": "[Your-api-key]", "applicationname": "SampleProject",
"type": "System.NullReferenceException", "errordate": "2018-10-23 10:47:17 "}'
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.net.ssl.HttpsURLConnection;
public class ErrLogSample {
public static void main(String[] args) throws Exception {
System.out.println("About to create an exception that will be sent to ErrLog.IO..");
try {
String str = null;
System.out.println(str.toUpperCase());
} catch (Exception ex) {
// Set up some variables
Date now = new Date();
String message = ex.getMessage();
String stackTrace = ex.toString();
StackTraceElement ste = ex.getStackTrace()[0];
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = df.format(now);
String apikey = "[Your-api-key]";
String postString =
"{" +
"\"apikey\": \"" + apikey + "\",\n" +
"\"message\": \"" + message + "\",\n" +
"\"errordate\": \"" + formattedDate + "\",\n" +
"\"applicationname\": \"Java Sample\",\n" +
"\"trace\": \"" + stackTrace + "\",\n" +
"\"method\": \"" + ste.getMethodName() + "\",\n" +
"\"lineno\": "+ ste.getLineNumber() + "\n" +
"}";
System.out.println(postString);
URL url = new URL("https://relay.errlog.io/api/v1/log");
byte[] postData = postString.getBytes(StandardCharsets.UTF_8);
int postDataLength = postData.length;
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("User-Agent", "Java Test Application");
conn.setRequestProperty("Content-Length", Integer.toString(postDataLength));
DataOutputStream os = new DataOutputStream(conn.getOutputStream());
os.write(postData);
int responseCode = conn.getResponseCode();
String responseMessage = conn.getResponseMessage();
System.out.println("");
System.out.println("ResponseCode: " + responseCode);
System.out.println("Message: " + responseMessage);
os.flush();
os.close();
}
}
}
Note: This code relies on having
the LWP modules installed. See
http://search.cpan.org/dist/libwww-perl/lib/LWP.pm
for more info.
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://relay.errlog.io/api/v1/log";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('content-type' => 'application/json');
my $post_data = "
{\"apikey\": "[Your-api-key]\",
\"message\": \"null\",
\"errordate\": \"2024-12-22 05:09:13\",
\"applicationname\": \"Perl Sample\",
\"trace\": \"The function I'm in\",
\"method\": \"main\",
\"lineno\": 19
}";
$req->content($post_data);
my $resp = $ua->request($req);
if ($resp->is_success) {
my $message = $resp->decoded_content;
print "Received reply: $message\n";
}
else {
print "HTTP code: ", $resp->code, "\n";
print "HTTP message: ", $resp->message, "\n";
}
Variable |
Type |
Required |
Description |
apikey |
string |
required |
This is your ErrLog.IO apikey. |
message |
dynamic |
required |
This is the error message that you want logged. |
type |
dynamic |
recommended |
This is the type of event you're logging. In C# it could be "NullReferenceException",
"ArgumentException" or just "Exception". |
applicationname |
dynamic |
recommended |
This is the name of the application that caused the event. Helpful for distinguishing
different applications. |
errordate |
dynamic |
optional |
The datetime the event occurred. Should be in the format yyyy-mm-dd hh:mm:ss where
specified. |
querystring |
dynamic |
optional |
The querystring of the request which caused the event. |
trace |
dynamic |
optional |
This is the stacktrace of the exception. |
page |
dynamic |
optional |
This is the page in which the event occurred |
method |
dynamic |
optional |
This is the method in which the event occurred |
lineno |
int |
optional |
The line number of the code which caused the event. |
colno |
int |
optional |
The column number of the code which caused the event. |
filename |
dynamic |
optional |
The filename of the code which caused the event. |
useragent |
dynamic |
optional |
This is the useragent string for the client's browser |
browsername |
dynamic |
optional |
This is the browser the client was using when the event occurred. |
servername |
dynamic |
optional |
This is an identifier for the server/device on which the event occurred. |
browser_capabilities |
dynamic |
optional |
This is identifies the capabilities of the client's browser |
ipaddress |
dynamic |
optional |
This is the IP address of the client device. |
custom |
dynamic |
optional |
This can be used to store any additional data you want. |
language |
dynamic |
optional |
This is the programming language the code was written in. |
session_data |
dynamic |
optional |
Represents a HttpSessionState object. |
assemblyversion |
dynamic |
optional |
You can use this to represent the version of your application/library. |
application_data |
dynamic |
optional |
Used to store name/value data from your Application state. |
request_header |
dynamic |
optional |
This is used to store the HTTP Request Headers as name/value pairs. |
request_formdata |
dynamic |
optional |
This is used to store the HTTP Request Form Data as name/value pairs. |
request_cookies |
dynamic |
optional |
This is used to store the HTTP Cookies as name/value pairs. |
environment |
dynamic |
optional |
This is used to store general environment metrics as name/value pairs. |
The Webhook API will return a plain-english error message describing any issues it encounters when you POST an error to it.
Missing API Key |
The API key is a mandatory field and required for the API to correctly function. |
Incorrect usage of Webhook |
A HTTP POST is the method used to send data to the Webhook. GET and other HTTP methods are not supported. |
Discuss this article