AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 24.04.2012, 02:13   #1  
Blog bot is offline
Blog bot
Участник
 
25,626 / 848 (80) +++++++
Регистрация: 28.10.2006
Axilicious:Ax 2012 and ETW (Event Tracing for Windows)
Источник: http://www.ksaelen.be/wordpresses/dy...g-for-windows/
==============

Now let’s get into to business quick and start off with a question : “How often did you want to reproduce / debug a certain process without actually knowing where the source of the problem may reside?”

Well the answer to that question for most of us will be : “Quite a lot” and then this would be followed immediately with the question : “Did you then create data log tables to store values, stack traces, information messages, …?” And again the answer will be often : “Yes”

Now this will probably help you out : ETW!

I will not go into the full details of Event Tracing for Windows as this would definately take us too far, but here’s a link where you can do some additional reading : http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

What we will look at for this post is how we can make advantage of ETW to do some tracing within Dynamics Ax 2012. Specifically we are going to make a custom piece of code do output some informational messages that can be caught by a data collector set using Perfmon and viewed by the Event viewer.

The following question may arise : “Why would we want ETW to handle the tracing and not stay in our habitat of X++ and storing data in tables?” Well the answer to this is:
  • ETW by far does not cause as many overhead as normal logging would do. Both for execution time (CPU) and diskspace.
  • If your code is ETW ready, you can do logging in production environments by starting / stopping data collector sets.
  • If your code is ETW ready, logging does not need to be built when needed but will immediately be available when needed.
  • The log files can be used in Event Viewers and also SCOM so it helps system administrators to know what is going on in the black box Dynamics Ax.
So let us jump in and create the data collector set.

First start op by opening perfmon and navigate to the user defined data collector sets.



Right click and create a new data collector set.













After the creation of the data collector set, right click it and you can start / stop the collection of ETW events.

But now that we have the collection part, we also need to make custom code trigger some events from within Dynamics Ax. And that is where the xClassTrace  class comes into play. The xClassTrace class is used to make advantage of ETW and is used to start / stop traces to files, log component messages in ETW to be caught by data collector sets, …

So let us take a look at some sample code that loops all customers and logs a component message in ETW to be caught. (Please not the isTracingEnabled checks to make sure string formatting will only be done when needed to have the minimum amount of performance overhead)

static void KeSae_ETW_LogComponentMessageTest(Args _args){ CustTable theCustomer; ; if(xClassTrace::isTracingEnabled()) { xClassTrace::logComponentMessage('AxTracing',"Starting ETW tracing"); } while select theCustomer { if(xClassTrace::isTracingEnabled()) { xClassTrace::logComponentMessage('AxTracing',strFmt("Processing customer %1", theCustomer.AccountNum)); } } if(xClassTrace::isTracingEnabled()) { xClassTrace::logComponentMessage('AxTracing',"Starting ETW tracing"); }}

Now that our code is ready to log some messages, start the data collector set in the perfmon tool and run the sample code. After running the code, go ahead and stop the data collector set. The result will be a log file generated that can be openened by the Event Viewer as seen below where we can actually see the logged messages from within Dynamics Ax.





So this is a very simple example, but this logging method is the way to go when you want efficient, performing logging in your system! This way you can minimize the logging overhead.




Источник: http://www.ksaelen.be/wordpresses/dy...g-for-windows/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
axperf: Dynamics AX Trace Parser Update 2 Blog bot DAX Blogs 4 27.06.2011 15:07

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 06:58.