log.jod.li
It often happens that we need to gather logs from several sources. Centralising them in one simple server place is the purpose of the log.jod.li initiative. The logs are then visible almost instantaneously on the log.jod.li page or can be retrieved in a format similar to CSV (raw logs). For more details, please visit https://log.jod.li .
C# situation
This page aims at showing how to use log.jod.li logs centralisation solution using C# code.
Let’s say you have some C# code that may not always run as expected. You want to track the unwanted outcomes and centralise their reading on log.jod.li . You could read your C# logs from C# dedicated solutions but you would not be able to see the logs at the same place from your C# programs and those written in completely different technologies. So, if you wish to centralise your logs from C# program, you can use a simple GET call to a URL containing:
- The server name to send the log to the right location. This will be en.log.jod.li .
- The user name you created on log.jod.li .
- The user key you received in your email box when you created your user. Make sure nobody else gets access to your key.
- The log message that you want to record on the log.jod.li server. The maximum length of the message is 1700 characters. It must be passed url encoded so that the string is interpreted correctly by the server.
- Optionally the application name so that you can filter your logs more easily. Max 32 characters.
- Optionally the client guid so that you can filter on a given client. Max 32 characters.
Here is an example of URL:
https://en.log.jod.li/?api=a&u=toto&k=1234567890123456&a=AppName&c=ClientGUID&m=testing
Here, the user is “toto”, the key is “1234567890123456”, the application name is “AppName”, the client guid is “ClientGUID” and the log message is “testing”.
Send log with a GET call
What we can do to make use of log.jod.li in this case is using a simple function to call a URL similar to the one mentioned above. Here is the function and the call to it:
using System; using System.Net.Http; public class Program { public static void Main() { log("Message sent through GET"); } public static void log(String message){ using (var client = new HttpClient()) { var responseString = client.GetStringAsync("https://en.log.jod.li/?api=a&u=lcuis&k=WP4lT1d0Relv9wmW&c=ClientGUID&a=AppName&m=" + Uri.EscapeUriString(message)).Result; System.Console.WriteLine(responseString); } } }
Here is the outcome of the call on log.jod.li web page:
2018-09-22 11:35:06 ClientGUID AppName Message sent through GET
Here is the outcome in the raw CSV format:
2018-09-22 11:35:06,ClientGUID,AppName,Message sent through GET
Conclusion
This is a demonstration that you can log your messages by simply calling a url from C# code. This is especially useful if you have several technologies for which you need to read logs.