Open Closed

Serilog is only logging errors from the HttpApi.Host #6710


User avatar
0
abpnewtonvisionco created
  • ABP Framework version: v7.2.2
  • UI Type: Angular
  • Database System: EF Core (SQL Server)
    • Auth Server Separated (for Angular)**: yes

Hey Guys,

We want to use the serilog sinks to log what ever issue happens inside the Application layer of the microservices. However I added the configuration for the sinks and when I throw an issue in the Application layer it is never picked up in the logs.

I have this configuration in the Program.cs file in the HttpApi.Host.

On the file it only writes what I have in the line 35, besides that It never gets an error.

This is how I am throwing an error and logging it using ILogger in the AppService under the project Application:

This is my file:

What else should I add to the configuration to make it work?

Let me know if I can provide more information

Thanks!


11 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Each website has its log configuration. They are usually written to the Logs.txt. If you want all website logs written to a single file. You can configure a shared log file.

  • User Avatar
    0
    abpnewtonvisionco created

    hi

    Each website has its log configuration. They are usually written to the Logs.txt.
    If you want all website logs written to a single file. You can configure a shared log file.

    Hi Maliming actually what I need is to send them via email with send grid and also record them in the application insight, however I am doing a proof of concept. And what I found in this test is that it doesn't write to the log file that I specified. However with what you mentioned could be a reason on why it is not writting to the file I mention.

    How can I achieve to send the error logs to the email? I tried using

    .WriteTo.Email( fromEmail: "thisisanexample@example.com", toEmail: "cijal75666@minhlun.com", mailServer: "smtp.sendgrid.net", restrictedToMinimumLevel: LogEventLevel.Error )

    but it doesnt work, that's why I was checking if the file log worked. but it didnt...

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    but it doesnt work, that's why I was checking if the file log worked. but it didnt...

    You can test your mail sender configuration via https://github.com/abpframework/abp-samples/tree/master/EmailSendDemo https://github.com/serilog/serilog-sinks-email/blob/dev/src/Serilog.Sinks.Email/Sinks/Email/MailKitEmailTransport.cs#L24-L37

  • User Avatar
    0
    abpnewtonvisionco created

    hi

    but it doesnt work, that's why I was checking if the file log worked. but it didnt...

    You can test your mail sender configuration via https://github.com/abpframework/abp-samples/tree/master/EmailSendDemo https://github.com/serilog/serilog-sinks-email/blob/dev/src/Serilog.Sinks.Email/Sinks/Email/MailKitEmailTransport.cs#L24-L37

    Hi Maliming thanks for the answer, I don't require to do any other configuration in the Program file?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You need to make sure your email sender configuration is correct.

    Then use WriteTo.Email in all projects that want to use email to output logs.

    https://github.com/serilog/serilog-sinks-email

  • User Avatar
    0
    abpnewtonvisionco created

    hi

    You need to make sure your email sender configuration is correct.

    Then use WriteTo.Email in all projects that want to use email to output logs.

    https://github.com/serilog/serilog-sinks-email

    Hi Maliming,

    Thanks I'll review it as soon as possible and will ask if I got any other question. Thanks again!

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    sure. no problem. : )

  • User Avatar
    0
    abpnewtonvisionco created

    sure. no problem. : )

    Hi Maliming, we got a project were we are sure the emailing is working, however I still can't make the serilog send an email with the error, is there any demo for this with ABP? I couldn't find any information about this.

    Also when adding the Sink for file/console it is only logging the httpapihist errors, not the one in the other layers, how can we implement so we see the erros from all the layers ? As I am sure if I fix the email issue I will only get the errors from the httpapihost layer

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    we got a project were we are sure the emailing is working, however I still can't make the serilog send an email with the error, is there any demo for this with ABP? I couldn't find any information about this.

    Can you share the email SMTP info with me? I will test it on my local. liming.ma@volosoft.com

    Also when adding the Sink for file/console it is only logging the httpapihist errors, not the one in the other layers, how can we implement so we see the erros from all the layers ? As I am sure if I fix the email issue I will only get the errors from the httpapihost layer

    Like I said. Each website has its log configuration. You need to configure them to output logs to a data source.

  • User Avatar
    0
    abpnewtonvisionco created

    I was finally able to make it work. For everyone who wonders, you'll need to add the configuration in the "Shared.Hosting" project. under the class SerilogConfigurationHelper. There I used the nuget for SerilogSinksSendgrid and done

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Thanks abpnewtonvisionco

Made with ❤️ on ABP v9.1.0-preview. Updated on December 26, 2024, 06:07