Closed abolfazlmohammadiseif closed 5 years ago
@abolfazlmohammadiseif You'll need to setup a RabbitMQ instance. Then in your "console App", you add this library, and configure it to write logs to the RabbitMQ instance. In your "another App", you can use the official .NET RabbitMQ.Client library here: https://www.rabbitmq.com/dotnet.html
Good luck.
Hi again, thanks for answering my question. In a .NetCoreWebApp, I've added the following code in Startup.cs , inside 'ConfigureServices' method.
var config = new RabbitMQClientConfiguration
{
Port = 5672,
DeliveryMode = Serilog.Sinks.RabbitMQ.RabbitMQDeliveryMode.Durable,
Exchange = "",
Username = "guest",
Password = "guest",
ExchangeType = "fanout",
Hostnames = { HostName },
};
var logger = new LoggerConfiguration()
.WriteTo.RabbitMQ((clientConfiguration, sinkConfiguration) =>
{
clientConfiguration.From(config);
sinkConfiguration.TextFormatter = new JsonFormatter();
}).CreateLogger();
var loggerFactory = new LoggerFactory();
loggerFactory
.AddSerilog()
.AddConsole(LogLevel.Information);
services.AddSingleton<ILoggerFactory>(loggerFactory);
then i've injected in the Home controller, the following:
ILogger _logger;
public HomeController(ILoggerFactory logger)
{
_logger = logger.CreateLogger(typeof(HomeController));
}
then ive used like this:
_logger.LogInformation("My Message");
Is there anything else I should do? I mean
1- where should I add 'QueueName' and 'connection' and 'channel'?
2- what is the configuration in Receiver App and the diffrence between the Sender App?
Thanks
@abolfazlmohammadiseif
Serilog.Sinks.RabbitMq doesn't 'as such' support Queue, but again, you can still do it. Find an example of that in the Unit tests. https://github.com/sonicjolt/serilog-sinks-rabbitmq/search?q=QueueName&unscoped_q=QueueName
Hi, Im going to use this project in my for example console App. I want to send logs to rabbitmq and receive in another App. what are the steps? Thanks