Reputation: 689
I want to use log4net for my windows service application to write logs but without using xml. A piece of code would help. Thank You
Upvotes: 2
Views: 1746
Reputation: 13419
You can configure log4net
to use whatever type of appender you like, not just XML
. See here for many different kinds of appenders.
You can configure it in your Web.config
(or App.config
) like this, for example:
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender, log4net">
<param name="File" value="Log\Log.NHibernate.txt" />
<param name="AppendToFile" value="false" />
<layout type="log4net.Layout.PatternLayout, log4net">
<param name="ConversionPattern" value="%m%n" />
</layout>
</appender>
<!-- Note: Priority level can be ALL/DEBUG/INFO/WARN/ERROR/FATAL/OFF -->
<root>
<priority value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
Upvotes: 0
Reputation: 13976
I think you mean that you do not want an external configuration file for log4net, but you want it embedded in your app.config or web.config.
Configuring it from code is not a good idea. You often need to maintain that configuration, change file location, change log size, etc. So you need an easily accessible location to do it.
Here's an article that shows you how to embed the log4net configuration in your application configuration file.
Upvotes: 1