Category Archives: Visual studio

Earlier I had posted about how to achieve File based logging in Ax, however after working with log4net on another project with .net I decided to implement debugging with Ax2012. This is because popping messages in the info log isint a very refined, besides at a customers site, after turning a few configuration keys on, the logging messages can be traced without writing extra code.

Log4Net: This is a very versatile library, if you look at the configuration files or Google around this, you will notice that it supports a wide variety of logging facilities and filters that can be applied. The overhead of using this library isint much.

The advantage of using is that the logging messages can be left inside the code (and you can even mark their category, and it can be configured in a certain way so that the debugging mechanism can be switched turned on or off for that category.

Implementing log4net in AX2012:

You could follow one of these posts and run an independent c# console project and test the log4net framework like in this blog. I wont be going through that part. What i will be showing is how to implement a library once created and added to AX2012, as AX2012 has its own configuration file which will need to be amended.

The C# project:

Create a C# project, add it to the AOT and add the log4net.dll to the c# project. Note that if you use Nuget there are issues adding it into Ax as the dll needs to be referenced with Ax too. So NuGet will not exactly help.

Create a config file called log4net.config (and this can be duplicated across to the AOS Server – More later)
Add the log4Net assembly to AX references. This is because the log4net assembly doesn’t get uploaded to the server directory, this double up is required as the log4net dll may not be stored in the csharp project in the AOT. Once this is done, then we are ready to call it from X++ or from other C# projects.

Now when you were creating the c# project you would have realized that you added parts to the configsections tag in the app.config and also added the log4net tags. These settings need to be transferred into the Ax config file. So in the applications server directory you will see a file ax32serv.exe.config , this is the file where you need to add the values too (: this is the same file where AIF services are registered)
Make the changes to the ax32serv.exe.config file so that we can start programming.

Log4Net’ing from X++
I create a Class called Class1 (a very original name)

public static server void writeLog()
{
//This uses the default log name - which is hardcoded in my project
System.Exception exc;
SHSAx.Logger.AxLogging logging;
SHSAx.Logger.AxLogging::Write(SHSAx.Logger.LogType::Info, "this is an info");
SHSAx.Logger.AxLogging::Write(SHSAx.Logger.LogType::Debug, "this is a debug");
SHSAx.Logger.AxLogging::Write(SHSAx.Logger.LogType::Error, "this is an Error");
SHSAx.Logger.AxLogging::Write(SHSAx.Logger.LogType::Fatal, "this is an Fatal issue");
SHSAx.Logger.AxLogging::Write(SHSAx.Logger.LogType::Warn, "this is a Warning");
}

I called these methods from a job to show the results. Note that this is a Server side solution. If you want this to be a client side then you may have to deploy the DLL to every client PC. For me calling a method on the server works well and all logs can be written on the server side.
You could dynamically create lognames based on the user, and then create an appender to capture only those messages.

Once done restart the AOS service and run the job.MyFirstLoggerAx000001.log

NOTE: to pick up the new C# project in X++ you may have to restart the AOS service. Also because we are reloading the configuration every time we call the logging class, there will be overheads. It will nice if the config file doesnt need to be changed.

Hopefully this can be turned into a more streamlined approach and we can get a common class / interface that we all can use to do some logging.

I was faced with the issue to create a user management in one of my applications, which allowed the user to only gain access to certain features of the Application.

Inititally, all the business required was to set up a user level, and then according to that level they would want the program to be hardcoded to allow access to users with atleast that access level..

Sounded a bit abnormal as the number of users was not small..it was medium and potential to grow, especially when the application had a possibility to be setup for other similar organizations.

So I then created this user group management, when you could create groups, and assign which features or programs the group had access to. Users could then be alloted to those groups. However certain users might be required to have access to some indiviadul features only, so that was also covered. I created this and applied it to a Windows forms, using 3rd party controls (Devexpress) and with its ribbon tabs, i could only show those tabs and those feature buttons to which the user had access to.

I had already started this from home, and created the management console in pure windows forms. Not as nifty as the 3rd party controls, but then serves the purpose in a similar way.I created it as a DLL with its own database, however I was challenged with creating the strongly typed database to have access only to the database defined in the application refrencing this library.

The only catch to it is that the User’s ID has to be in an integer format. Looking at this tool, It can be integrated into the management features, and can be used straigt from the box (just need to setup the database).

This is filed under the LGPL Licence, so feel free to change anything in it and crete your own library from it.

At the moment, most of the code is within the form classes, So my next level to this is to split assignments into pure cs files so that the library can be used to build your own UI, rather than relying on the one provided within it. (Its not that bad)

Unfortunately unlike eclipse it dosent use the same shortcut to comment and uncomment the code.

Another good editing shortcut:Have you ever tried to delete a line, and then started to use backspaces or del keys to format the code?Well…if you do want to remove the line completely….even without selecting the whole linepress Shift + Del and the line will dissapear without affecting anything else