Log4NetAdoNetAppender icon indicating copy to clipboard operation
Log4NetAdoNetAppender copied to clipboard

Api logger sending null entries to DB leading to exception without any post api call

Open Ghannu96 opened this issue 1 year ago • 11 comments

I have used this log4netappender for logging in 3 cases in my application. The API appender is triggered automatically multiple times with null entries leading to DB exception for NOT NULL column. The custom code for API logging only runs in case of POST calls.

DB : PostgreSQL 15 Dot Net : .NET 5.0

Please help as I am unable to find the root cause for this. I think it could be because of the log4net DLL version 2.0.14 we are using.

image

Thanks

Ghannu96 avatar Mar 30 '23 07:03 Ghannu96

Can you show the full stacktrace?

microknights avatar Mar 30 '23 09:03 microknights

Can you show the full stacktrace? Full means the complete snapshot?

Ghannu96 avatar Mar 30 '23 14:03 Ghannu96

image On Line 92 we have Log.info() called to log to console. I suppose it is futher trigerring the apilogger automatically.

Let me know your thoughts.

Thanks

Ghannu96 avatar Mar 30 '23 14:03 Ghannu96

That is the callstack, i rather see the stacktrace (as text) and if possible with all inner exceptions. I am pretty sure it is not the appender that is the problem, but the data being send through.

What happens if you use a console/file appender?

microknights avatar Mar 31 '23 07:03 microknights

That is the callstack, i rather see the stacktrace (as text) and if possible with all inner exceptions. I am pretty sure it is not the appender that is the problem, but the data being send through.

What happens if you use a console/file appender?

So the console appender is working fine and logging to console. I am not able to find out the source of data which is null for all fields in this case of api logging. Somehow it is triggered on its own. The custom logic is supposed to work on POST call.

Ghannu96 avatar Mar 31 '23 07:03 Ghannu96

My answer is that a null is being passed to the logger property userid which leads to the NOT NULL violation from the database. This also explains why the console logger works, since it does not have the NOT NULL violation.

Is the error always happening, or only sometimes?

microknights avatar Mar 31 '23 09:03 microknights

My answer is that a null is being passed to the logger property userid which leads to the NOT NULL violation from the database. This also explains why the console logger works, since it does not have the NOT NULL violation.

Is the error always happening, or only sometimes?

Console logger is not logging into DB, the exception is due to the NULL userid value being passed to the table linked to ApiLogAppender, I debugged it, it is not passed from the custom code we have written. I am just redirected to error handler with the exception w/o any source trace from where I can see the null data being passed.

It happens all the time whenever we make an api call usually GET also, we can see this error being logged in our console.

Ghannu96 avatar Mar 31 '23 09:03 Ghannu96

well, it is either a misconfiguration or data is actually null. The Appender just pass the data it get.

You can post your log4net config, and the appender config - maybe it will enlight something.

microknights avatar Mar 31 '23 09:03 microknights

log4net attached. Check the APISQL appender. Please suggest.

testlog4net.txt

Ghannu96 avatar Mar 31 '23 10:03 Ghannu96

Seems correct, I would put the \"userid\" in the console logger, and disable the database appenders. Then you can see if userid is null (empty) while logging.

microknights avatar Mar 31 '23 14:03 microknights

Thanks for your suggestion, I checked in my code, The Log Info/Log Debug statements written for custom logging of API calls are triggering the API ado net appender call. The appender and Log statements are a part of same assembly. Any way we can prevent appender from getting called in case of usual request/response logs? It should be triggered in POST call only.

I commented all the log statements, I don't see the above mentioned error of null userid issue after that.

Thanks

Ghannu96 avatar Apr 26 '23 07:04 Ghannu96