Targets¶
Configuration¶
NuLog comes with a number of built-in targets. Targets are configured within the <targets>
section of the NuLog configuration:
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="nulog" type="NuLog.Configuration.ConfigurationSectionHandler, NuLog" />
</configSections>
<nulog>
<!-- ... -->
<targets>
<target name="mytarget" type="NuLog.Targets.TraceTarget" />
</targets>
<!-- ... -->
</nulog>
</configuration>
|
All targets must have a name
and a type
:
- name - The name identifies the target to the various rules.
- type - The type indicates the concrete type of the target. When referencing the built-in NuLog targets, you can omit the assembly name from the type string; but if you are referencing a third party, or custom target, you’ll need to include the assembly, as is standard when identifying a type: “Some.Assembly.Namespace.Path.ToATarget, Some.Assembly”.
Trace Target¶
NuLog.Targets.TraceTarget
The trace target writes log events to Trace:
1 2 | <target name="mytrace" type="NuLog.Targets.TraceTarget"
layout="${DateTime:'{0:MM/dd/yyyy}'} | ${Message}\r\n" />
|
The trace target has the following properties:
- layout - Optional - Defines the layout format for the target. By default, this is a standard layout, as documented in Layouts/Log Format.
Console Target¶
NuLog.Targets.ConsoleTarget
The console target writes log events to Console:
1 2 | <target name="myconsole" type="NuLog.Targets.ConsoleTarget"
layout="${DateTime:'{0:MM/dd/yyyy}'} | ${Message}\r\n" />
|
The console target has the following properties:
- layout - Optional - Defines the layout format for the target. By default, this is a standard layout, as documented in Layouts/Log Format.
Color Console Target¶
Documentation coming soon.
- background - Optional - An optional override to the Background Color of messages written to the console.
- foreground - Optional - An optional override to the Foreground Color of messages written to the console.
Text File Target¶
NuLog.Targets.TextFileTarget
The text file target writes log events to a text file:
1 2 3 | <target name="mytarget" type="NuLog.Targets.TextFileTarget"
path="app.log"
layout="${DateTime:'{0:MM/dd/yyyy}'} | ${Message}\r\n" />
|
The text file target has the following properties:
- path - Required - The path to the text file to log to. Can be relative, or absolute.
- layout - Optional - Defines the layout format for the target. By default, this is a standard layout, as documented in Layouts/Log Format.
Mail Target¶
NuLog.Targets.MailTarget
The mail target sends log events via a SMTP server:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <target name="mytarget" type="NuLog.Targets.MailTarget"
subject="Unhandled Exception in Super App!"
to="me@superawesome.net"
from="system@superawesome.net"
smtpServer="mail.gtm.superawesome.net"
body="The message proceeds: ${Message}"
html="false"
convertNewlineInHtml="false"
smtpUserName="superuser"
smtpPassword="awesomepass"
enableSsl="true"
smtpPort="993"
smtpDeliveryMethod="Network"
pickupDirectory="nope"
timeout="1042" />
|
The mail target has the following properties:
- subject - Required - The subject line of the email. This is a layout format, as documented in Layouts/Log Format.
- to - Required - A semi-colon delimited list of email addresses to send the email to.
- from - Required-ish - Required if not set in the application/web config, in the
<system.net>
section. The email address to send the message “from”.- smtpServer - Required-ish - Required if not set in the application/web config, in the
<system.net>
section. The network address of the SMTP server to send email messages through.- body - Optional - An optional override for the layout format for the body of the email. By default, this is a standard layout, as documented in Layouts/Log Format.
- html - Optional - If set to true, signals that the body of the email is HTML. Defaults to false.
- convertNewlineInHtml - Optional - If set to true, replaces newline characters in the body of the email with
<br />
tags.- smtpUserName - Optional - The username for authenticating to the SMTP server. If given, the password is required:
- smtpPassword - Optional-ish - The password for authenticating to the SMTP server. Required if the user name is given.
- enableSsl - Optional - If set to true, will use SSL when connecting to the SMTP server.
- smtpPort - Optional - The port to connect to the SMTP server on.
- smtpDeliveryMethod - Optional - The SMTP Delivery Method for sending the email through. Defaults to
Network
.- pickupDirectory - Optional-ish - Required if SpecifiedPickupDirectory is set for the smtpDeliveryMethod. The path of the directory to which to write mail messages.
- timeout - Optional - The timeout value, in milliseconds, for when connecting to the SMTP server to send a mail message.
Event Log Target¶
Logs to the Windows Event Log - documentation coming soon.