The XML File target automatically defaults to performing in place rolling. After 10,000 entries are reached, older items will be discarded. This behavior can be overridden. The connection to the file will be automatically closed if nothing has been written to the log for one second.
It has these properties that can be configured:
- Name - Defaults to XmlTarget
- LoggingMode - Defines which mode to use for the target; Synchronous, Buffered, or Asynchronous. The default is Synchronous.
- MessageFormat - What to output in the log. See the Message Format topic for more information.
- DateFormat - The date format for the %LogTime% variable in the MessageFormat. See the Date Format topic for more information.
- MinimumLevel - The minimum logging level to log a message.
- AssemblyNameFilter - If specified, only log for a specific assembly name. See the Filtering topic.
- NamespaceFilter - If specified, only log for a specific namespace. See the Filtering topic.
- ClassNameFilter - If specified, only log for a specific class name. See the Filtering topic.
- MethodNameFilter - If specified, only log for a specific method name. See the Filtering topic.
- ThreadNameFilter - If specified, logging will only occur for the thread id or thread name specified. See the Filtering topic.
- UserNameFilter - If specified, logging will only occur for the specific user name. See the Filtering topic.
- MachineNameFilter - If specified, logging will only occur for the specific machine name. See the Filtering topic.
- BufferSize - When a logging target has a Mode of Buffered, this is how often messages are committed. See the Buffered Logging topic.
- MaxLogEntries - The maximum entries before discarding old entries. Defaults to 10,000
- FileRollingStyle - What to do with old entries. Options are NoRolling, ArchiveMaxLogEntries, ArchiveSize, ArchiveTimePeriod, DiscardMaxLogEntries. The default is DiscardMaxLogEntries
- FileRollingMaxArchiveFiles - The maximum number of files to keep when the FileRollingStyle is ArchivingMaxLogEntries, ArchiveSize, or ArchiveTimePeriod
- FileRollingMaxSize - How often to archive log files when the FileRollingStyle is ArchiveTimePeriod
- FileRollingTimePeriod - How often to archive log files when the FileRollingStyle is ArchiveTimePeriod
- Header - The header for the XML target
- Footer - The footer for the XML target
- LogFilePath - The path to the log file
//Example runtime configuration, can also use log.config, app.config, or web.config
Log.ResetConfiguration();
XmlTarget target = new XmlTarget("log.xml");
Log.Config.Targets.Add(target);
Log.Debug("This is a test");
You can specify dynamic paths using these constructs:
Data Directory
http://stackoverflow.com/questions/1409358/ado-net-datadirectory-where-is-this-documented
|DataDirectory|\mylogfile.xml
Server.MapPath for ASP.NET, Web Services, and WCF
http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx
Server.MapPath("~/App_Data")\mylogfile.xml
Special Folders
http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx
%ApplicationData%\mylogfile.xml
%CommonApplicationData%\mylogfile.xml
%LocalApplicationData%\mylogfile.xm
%MyDocuments%\mylogfile.xml