<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Art Of Creation - Dynamics AX Blog &#187; Event Log</title>
	<atom:link href="http://www.artofcreation.be/tag/event-log/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.artofcreation.be</link>
	<description>The everyday life of a Dynamics AX developer</description>
	<lastBuildDate>Fri, 23 Jul 2010 16:29:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Writing in the event log from Dynamics AX</title>
		<link>http://www.artofcreation.be/2009/06/19/writing-in-the-event-log-from-dynamics-ax/</link>
		<comments>http://www.artofcreation.be/2009/06/19/writing-in-the-event-log-from-dynamics-ax/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 11:14:55 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[Batch]]></category>
		<category><![CDATA[Event Log]]></category>
		<category><![CDATA[System.Diagnostics]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=125</guid>
		<description><![CDATA[Writing to the event log in Windows using AX is very easy when you use the EventLog class from the System.Diagnostics namespace. The following job demonstrates how to use the EventLog class. static void EventViewer&#40;Args _args&#41; &#123; &#160; &#160; System.Diagnostics.EventLog eventlog; &#160; &#160; #Define.LogSource&#40;&#34;Dynamics AX&#34;&#41; &#160; &#160; #Define.LogName&#40;&#34;Dynamics AX Log&#34;&#41; &#160; &#160; &#160; &#160; ; [...]]]></description>
			<content:encoded><![CDATA[<p>Writing to the event log in Windows using AX is very easy when you use the EventLog class from the System.Diagnostics namespace. The following job demonstrates how to use the EventLog class.</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> EventViewer<span style="color: #000000;">&#40;</span>Args _args<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; System.<span style="color: #000000;">Diagnostics</span>.<span style="color: #000000;">EventLog</span> eventlog;<br />
&nbsp; &nbsp; #Define.<span style="color: #000000;">LogSource</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;Dynamics AX&quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; #Define.<span style="color: #000000;">LogName</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;Dynamics AX Log&quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; ;<br />
&nbsp; &nbsp; <span style="color: #007f00;">// check if the log already exists</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #000000;">&#40;</span><span style="color: #00007f;">!</span>System.<span style="color: #000000;">Diagnostics</span>.<span style="color: #000000;">EventLog</span><span style="color: #00007f;">::</span><span style="color: #000000;">SourceExists</span><span style="color: #000000;">&#40;</span>#LogSource<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// create new log</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; System.<span style="color: #000000;">Diagnostics</span>.<span style="color: #000000;">EventLog</span><span style="color: #00007f;">::</span><span style="color: #000000;">CreateEventSource</span><span style="color: #000000;">&#40;</span>#LogSource<span style="color: #00007f;">,</span> #LogName<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; eventlog <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> System.<span style="color: #000000;">Diagnostics</span>.<span style="color: #000000;">EventLog</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; eventlog.<span style="color: #000000;">set_Source</span><span style="color: #000000;">&#40;</span>#LogSource<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// write info entry</span><br />
&nbsp; &nbsp; eventlog.<span style="color: #000000;">WriteEntry</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;Just writing in the event viewer.&quot;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #007f00;">// write error entry</span><br />
&nbsp; &nbsp; eventlog.<span style="color: #000000;">WriteEntry</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;Error! Please check the stack trace below. <span style="color: #000000;">\n</span><span style="color: #000000;">\n</span>&quot;</span> <span style="color: #00007f;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; con2str<span style="color: #000000;">&#40;</span>xSession<span style="color: #00007f;">::</span><span style="color: #000000;">xppCallStack</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #00007f;">,</span> System.<span style="color: #000000;">Diagnostics</span>.<span style="color: #000000;">EventLogEntryType</span><span style="color: #00007f;">::</span><span style="color: #000000;">Error</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #007f00;">// write warning entry</span><br />
&nbsp; &nbsp; eventlog.<span style="color: #000000;">WriteEntry</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;Job finished.&quot;</span> <span style="color: #00007f;">,</span> System.<span style="color: #000000;">Diagnostics</span>.<span style="color: #000000;">EventLogEntryType</span><span style="color: #00007f;">::</span><span style="color: #000000;">Warning</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; info<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;Check the event viewer!&quot;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>A possible use for this is when monitoring batch jobs.<br />
Tested using AX 2009, XP Pro. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2009/06/19/writing-in-the-event-log-from-dynamics-ax/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
