Log4NetAdoNetAppender
Log4NetAdoNetAppender copied to clipboard
Api logger sending null entries to DB leading to exception without any post api call
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.
Thanks
Can you show the full stacktrace?
Can you show the full stacktrace? Full means the complete snapshot?
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
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?
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.
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?
My answer is that a
null
is being passed to the logger propertyuserid
which leads to theNOT NULL violation
from the database. This also explains why the console logger works, since it does not have theNOT 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.
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.
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.
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