1
0
tinklu-paslaugos/Lab4/ParticipantRabbitMQ/Participant.cs
2024-12-07 17:21:09 +02:00

61 lines
1.5 KiB
C#

using ChatRoomContract;
using NLog;
using Participant;
namespace ParticipantRabbitMQ;
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;
}
/// <summary>
/// Entry point
/// </summary>
static void Main()
{
Logger log = LogManager.GetCurrentClassLogger();
ConfigureLogging();
while (true)
{
var chatRoom = new ChatRoomRabbitMQClient(
RabbitMQConfig.CreateConnection(),
RabbitMQConfig.ExchangeName,
RabbitMQConfig.CreateClientQueueName(),
RabbitMQConfig.ServerQueueName
);
var participant = new ParticipantLogic(chatRoom);
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);
}
}
}
}