i have 2 appender in web config ,first one save logs in xml file , and another save logs using external API , my issue is :
i need to set my default appender is to call external API just , no need to save on xml file , and if api reutred failed , i want to use logging by xml file ( i did it at run time). main question : how to set first appender is default for logging in web.config file
web.config :
<log4net>
<!--workflow logging-->
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >
<param name="File" value="C:/Workspaces/workflowLog/workflow-info.xml" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="Tahaluf.Workflow.Common.Core.Log.WorkFlowXmlLayout" />
</appender>
<!--Connect to Tahaluf Logging-->
<appender name="WorkFlowAppender" type="Tahaluf.Workflow.Common.Core.Log.WorkFlowAppender">
</appender>
<root>
<level value="ALL" />
<appender-ref ref="WorkFlowAppender" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
Only set your default appender in your web.config. You want to use the
WorkFlowAppender
, so remove theLogFileAppender
.If you need to use your
LogFileAppender
later, you add it by code.Take a look at this post, too.
Edit This solution doesn't work when the appender-ref of
LogFileAppender
is not set.The solution is to modify the
Threshold
of the appender.web.config:
Add method:
Turn appender off:
SetThreshold("LogFileAppender", log4net.Core.Level.Off);
Turn appender on:
SetThreshold("LogFileAppender", log4net.Core.Level.Debug);
Level can be any valid level (not onlyDebug
)