Can’t add comments so posting as a new question.
I implemented the suggestion by Matthew Lock in this thread
Log4net creating custom levels
Which works fine if you set the log level to TRACE or ALL and just want log messages at an with a custom label. However if I try to edit my log4net config file and set the log level to this custom level ie:
<root>
<level value="CUSTOM" />
<appender-ref ref="RollingFileAppender" />
</root>
I get the following errors:
log4net:ERROR You have tried to set a null level to root.
log4net.Core.LogException: Error in the application.
My use case is I want to enable/disable certain log lines for very specific troubleshooting scenarios. My thought was add a custom level in between DEBUG and ALL at level 25000. Previously I was doing this by creating these log lines set to TRACE and then committing a change to set them to INFO when I needed them, then reverting that commit. I’ve had to do this enough times that I feel a better solution is in order. I don’t want to actually set the log level to TRACE or ALL because that turns on a bunch of other log lines too creating a lot of noise. TRACE in this case is being used more as an archive level or almost like a commented log. The alternative is wrapping each of these log lines in a conditional that checks a setting stored somewhere else like the app.config. Adding a bunch of conditionals like this seems excessive. Basically I want DEBUG level traces but with some additional specific log lines for a specific scenario, but I don’t want those log lines on all the time when it’s configured for DEBUG.
I believe the errors I’m getting are because the custom levels don’t exist in the sealed Log4Net Level class.