54 lines
1.3 KiB
C#
54 lines
1.3 KiB
C#
using ChatRoomContract;
|
|
using NLog;
|
|
using Bogus;
|
|
using Participant;
|
|
|
|
namespace ParticipantGrpc;
|
|
|
|
internal class Participant
|
|
{
|
|
/// <summary>
|
|
/// Configures logging subsystem.
|
|
/// </summary>
|
|
private static void ConfigureLogging()
|
|
{
|
|
var config = new NLog.Config.LoggingConfiguration();
|
|
|
|
var console =
|
|
new NLog.Targets.ConsoleTarget("console")
|
|
{
|
|
Layout = @"${date:format=HH\:mm\:ss}|${level}| ${message} ${exception}"
|
|
};
|
|
config.AddTarget(console);
|
|
config.AddRuleForAllLevels(console);
|
|
|
|
LogManager.Configuration = config;
|
|
}
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
Logger log = LogManager.GetCurrentClassLogger();
|
|
|
|
ConfigureLogging();
|
|
|
|
while (true)
|
|
{
|
|
var client = new ChatRoomGrpcClient("http://127.0.0.1:5000");
|
|
var participant = new ParticipantLogic(client);
|
|
|
|
try
|
|
{
|
|
participant.Run();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
//log whatever exception to console
|
|
log.Warn(e, "Unhandled exception caught. Will restart main loop.");
|
|
|
|
//prevent console spamming
|
|
Thread.Sleep(2000);
|
|
}
|
|
}
|
|
}
|
|
}
|