-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeadShotDotnetLib.cs
More file actions
54 lines (51 loc) · 1.72 KB
/
DeadShotDotnetLib.cs
File metadata and controls
54 lines (51 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System.Net.Mime;
using System.Text;
using System.Text.Json;
using DeadShotDotnetLib.Interfaces;
using DeadShotDotnetLib.Models;
namespace DeadShotDotnetLib;
public class DeadShotDotnetLib(DeadShotDotnetLibConfig config) : IDeadShotDotnetLib
{
public async Task<bool> SendAsync(LogModel log)
{
try
{
HttpClient hClient = new();
string url = $"{config.DeadShotHost}:{config.DeadShotPort}";
HttpRequestMessage req = new(HttpMethod.Post, url);
string body = JsonSerializer.Serialize(log);
HttpContent content = new StringContent(body, Encoding.UTF8, MediaTypeNames.Application.Json);
req.Content = content;
HttpResponseMessage res = await hClient.SendAsync(req);
res.EnsureSuccessStatusCode();
return true;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
return false;
}
}
public bool Send(LogModel log)
{
try
{
HttpClient hClient = new();
string url = $"{config.DeadShotHost}:{config.DeadShotPort}";
HttpRequestMessage req = new(HttpMethod.Post, url);
string body = JsonSerializer.Serialize(log);
HttpContent content = new StringContent(body, Encoding.UTF8, MediaTypeNames.Application.Json);
req.Content = content;
HttpResponseMessage res = hClient.Send(req);
res.EnsureSuccessStatusCode();
return true;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
return false;
}
}
}