Log File Settings
Jump to navigation
Jump to search
Back :
CSharp Reference Implementation
Direct components write diagnostics information. By default, they write diagnostics information log files and the event log. You can customize how diagnostics information is output by changing configuration settings.
You can also entirely replace the default logging system with custom logging.
You customize default diagnostics by editing a component's configuration file. Some components use .config files while others use Xml serialized .xml files. In either case, the settings and options are the same, but are expressed in different syntax.
Settings are expressed as objects in Health.Direct.Common.dll:
Table of Contents
Direct components write diagnostics information. By default, they write diagnostics information log files and the event log. You can customize how diagnostics information is output by changing configuration settings.
You can also entirely replace the default logging system with custom logging.
You customize default diagnostics by editing a component's configuration file. Some components use .config files while others use Xml serialized .xml files. In either case, the settings and options are the same, but are expressed in different syntax.
Settings are expressed as objects in Health.Direct.Common.dll:
namespace Health.Direct.Common.Diagnostics { // Use for .config files... public class LogFileSection {} // Used for raw Xml config files public class LogFileSettings {} }
config Files
These are classic .config files.
Components retrieve Diagnostics settings from a LogFileSection configuration section.
- Requirements: *Ensure that the Direct Config Sections are correct registered in your .config file*.
<configuration> <logging> <file directory="~\Log" name="dnsserver_${date:format=yyyyMMdd}" extension="log" /> <behavior rolloverFrequency="Day" loggingLevel="Debug" /> <eventLog threshold="Fatal" source="Health.Direct.DnsResponder.WinSrv" /> </logging>
/configuration/configSections/logging (Required)
- Class: Health.Direct.Common.Diagnostics.LogFileSection
Element |
Required |
file |
Yes |
behavior |
Yes |
eventLog |
No |
file Element
/configuration/configSections/logging/file
- Health.Direct.Common.Diagnostics.LogFileElement
Attribute |
Required |
Type |
Default |
Description |
directory |
No |
string |
~\Log |
Directory where log files are written. Typically, a full path to the directory. If prefixed with '~', the directory is considered a child of the directory where the component is running from. E.g. ~\Log |
name |
Yes |
string |
The file's name. Can be a format string used to build file names.
| |
extension |
No |
string |
log |
Extension for log file names. |
behavior Element
/configuration/configSections/logging/behavior
- Health.Direct.Common.Diagnostics.LogBehaviorElement
Attribute |
Required |
Type |
Default |
Description |
rolloverFrequency |
No |
string |
Day |
Defines the interval at which logging rolls over to using a fresh file.
|
loggingLevel |
No |
string |
Error |
Determines what information is written to a log.
|
eventLog Element
/configuration/configSections/logging/eventLog
- Class: Health.Direct.Common.Diagnostics.EventLogElement
Attribute |
Required |
Type |
Default |
Description |
threshold |
No |
String |
Fatal |
Any diagnostic info with level above this are also written to the Event Log. See LoggingLevel above for a list of options. |
source |
No |
String |
Health.Direct |
Event log source |
Xml Config Files
- Class: Health.Direct.Common.Diagnostics.LogFileSettings
- You can use the XmlSerializer to serialize/deserialize settings yourself.
{YourRootElement}/Log
<SmtpAgentConfig> <Log> <DirectoryPath>C:\inetpub\logs</DirectoryPath> <NamePrefix>gateway</NamePrefix> <RolloverFrequency>Day</RolloverFrequency> <Level>Debug</Level> </Log> </SmtpAgentConfig>
Element |
Required |
Type |
Default |
Description |
DirectoryPath |
Yes |
String |
Full path to location for log files | |
NamePrefix |
Yes |
String |
The file's name. Can be a format string used to build file names.
| |
Ext |
No |
String |
log |
Log file extension |
RolloverFrequency |
No |
String |
Day |
Defines the interval at which logging rolls over to using a fresh file.
|
Level |
No |
string |
Error |
Determines what information is written to a log.
|
EventLogLevel |
No |
String |
Fatal |
Any diagnostic info with level above this are also written to the Event Log. See LoggingLevel above for a list of options. |
EventLogSource |
No |
String |
Health.Direct |
Event log source |