NMonitoring Weave your application

Now have in one hand the application to monitor, and the other hand the aspect that will log some of the methods of your application.
You have now to connect (weave) the aspect to the methods you choose to log.

For doing that we will use the AspectDNG DLL and syntax.

Create a weaving file

First we have to create a config file (here aspectdng-sample_aspects.xml) that will explain to AspectDNG how to weave:

 
<AspectDngConfig 
	warnings="$(path)/Warnings.log" 
	weaving="$(path)/Weaving-log-MyAppliocation.xml" 
	debug="true">

	<Variables>
		<Variable name="path" value="C:\MyApplication\bin\Debug"/>
	</Variables>
	
    <TargetAssembly>$(path)\MyApplication.exe</TargetAssembly>
    <AspectsAssembly>$(path)\sample_aspects.dll</AspectsAssembly>
    <WeavedAssembly>$(path)\MyApplicationWeaved.exe</WeavedAssembly>
    
    <PrivateLocations>
        <PrivatePath>$(path)</PrivatePath>
    </PrivateLocations>

    <Advice>
      <AroundCall aspectRegExp="* *.SampleAspect::SqlExecuteAspect(*)" 	          targetRegExp="* System.Data.SqlClient.SqlCommande::Execute*(*)"/>
    </Advice>
</AspectDngConfig>

In this configuration file we describe that:

  • The Aspect is in sample_aspects.dll DLL (The Class Library containing your aspect).
  • The application to weaved is MyApplication.exe
  • The result (your application weaved) will be written to MyApplicationWeaved.exe.
  • The aspect (Advice) you want to weave: all from your aspect assembly that look likes ?* *.SampleAspect::SqlExecuteAspect?
  • and which method you want to log with this aspect : all from MyApplication.exe that call (AroundCall) something a like "* System.Data.SqlClient.SqlCommande::Execute*"

Weave !

Now we will use the AspectDNG library to weave from a command prompt.

 
C:\MyApplication\bin\Debug\>aspectdng.dll -debug ..\..\ aspectdng-sample_aspects.xml 
Weaving as specified in ..\..\ aspectdng-sample_aspects.xml
aspectdng took in 578 millis to weave 1 aspects
C:\MyApplication\bin\Debug\>

Check what you have done

You can check what has been done using:

  • The AspecDNG log file, defined in your config file
  • Reflector to watch the code produced by AspectDNG in MyApplicationWeaved.exe
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.