Jack Sp
Jack Sp

Reputation: 376

NLog asp.net core sends email automatically on error without logging it

This is a weird situation, NLog users usually contact when NLog does not send emails but I am contacting you because NLog is sending emails.

I configured NLog using UseNLog(). I have nlog.config file. Thats it. Nothing else is set to configure it.

Nlog.config file just have target set to email me.

I do not even inject Logger in any OData controller. It is a Asp.net Core project.

I am manually throwing exception from one of my controller. And it sends me email. I am not even calling Logger.LogError().

How is this happening?

Upvotes: 1

Views: 1483

Answers (1)

Julian
Julian

Reputation: 36770

NLog integrates with ASP.NET Core logging. That isn't only a logger abstraction, but also ASP.NET Core is writing logs to that abstraction (debug info, http calls, errors etc).

So if ASP.NET Core catches an exception, it will write to the logging abstraction and NLog is configured to process the logging with UseNLog and the nlog.config.

This will be probably more clear if you set-up the internal log of NLog, it shows the internals.

See also the getting started with NLog and ASP.NET Core 2, in the example below you will see some output examples.

Upvotes: 1

Related Questions