Parseable Docs

C#


Create a dataset

First, we'll need to create a dataset. This is a one time operation, and we recommend storing log entries with same schema in a single dataset. So, for example, you can use one dataset per application (given that all logs from that application have the same schema).

Console.WriteLine("Create dataset!");
var client = new HttpClient();
var logstream_name = "teststream";
var request = new HttpRequestMessage(HttpMethod.Put, String.Concat("http://localhost:8000/api/v1/logstream/", logstream_name));
request.Headers.Add("Authorization", "Basic YWRtaW46YWRtaW4=");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

Send logs to the dataset

After dataset is created, you can start sending logs to the dataset using HTTP POST requests.

Console.WriteLine("Ingest a log event to the created dataset!");
request = new HttpRequestMessage(HttpMethod.Post, "http://localhost:8000/api/v1/ingest");
request.Headers.Add("Authorization", "Basic YWRtaW46YWRtaW4=");
request.Headers.Add("X-P-Stream", logstream_name);
var content = new StringContent("{\"source_time\":\"2024-03-27T10:29:00.434Z\",\"level\":\"info\",\"message\":\"Application is failing\",\"version\":\"1.2.0\",\"user_id\":13912,\"device_id\":4138,\"session_id\":\"abc\",\"os\":\"Windows\",\"host\":\"112.168.1.110\",\"location\":\"ngeuprqhynuvpxgp\",\"request_body\":\"rnkmffyawtdcindtrdqruyxbndbjpfsptzpwtujbmkwcqastmxwbvjwphmyvpnhordwljnodxhtvpjesjldtifswqbpyuhlcytmm\",\"status_code\":300,\"app_meta\":\"ckgpibhmlusqqfunnpxbfxbc\", \"new_field_added_by\":\"ingester 8020\"}", null, "application/json");
request.Content = content;
response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
Console.WriteLine("Log event ingested successfully!");

Querying a dataset

Once you have started sending logs to a dataset, you can query the logs using standard SQL.

Console.WriteLine("Query the dataset!");
request = new HttpRequestMessage(HttpMethod.Post, "http://localhost:8000/api/v1/query");
request.Headers.Add("Authorization", "Basic YWRtaW46YWRtaW4=");
content = new StringContent("{\n    \"query\": \"SELECT * from teststream\",\n    \"startTime\": \"2024-03-27T00:00:00.000Z\",\n    \"endTime\": \"2024-03-28T23:59:00.000Z\"\n}\n", null, "application/json");
request.Content = content;
response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

On this page