-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListener.cs
More file actions
37 lines (30 loc) · 860 Bytes
/
Copy pathListener.cs
File metadata and controls
37 lines (30 loc) · 860 Bytes
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
using System;
using System.Net;
using HTTPServer.Formatters;
using HTTPServer.Loggers;
using HTTPServer.Providers;
namespace HTTPServer
{
public sealed class Listener
{
private static readonly HttpListener? _listener;
private static readonly ILogger? _logger;
private Listener() { }
static Listener()
{
try
{
_logger = new ConsoleLogger("Listener", new LoggerFormatter());
_listener = new HttpListener();
_listener.Prefixes.Add(string.Format($"{ConfigurationProvider.Domain}:{ConfigurationProvider.Port}/"));
_listener.Start();
_logger.Log("Listener started at port: " + ConfigurationProvider.Port);
}
catch (Exception ex)
{
_logger?.Log("Unable to start the listener: " + ex.Message);
}
}
public static HttpListener Get => _listener ?? throw new Exception("Listener not initialized.");
}
}