Create log file using .net API

By | April 30, 2015

Whenever we implement complex routines like uploading data etc., one major thing comes into the picture is creating log of each action performed in the routine. Logs are something which tells users where the process failed and what is the error. In case of Sage CRM, we often develop complex routines for which error logging is one of the most important factor which needs to be taken care of.

New Post: Save time with Case Suggestions on Customer Portal

Now, how to create logs? Using custom methods..?? Answer in NO. Here in this blog I will be explaining a simplest way to create log file for your custom routine implemented using Sage CRM .net API.

Sage CRM .Net API provides wide range of built in functions which reduces lot of time and provides better flexibility while implementation. There is a method named LogMessage in .Net API. This method can be used in three ways as shown below.

1. LogMessage(string message);
2. LogMessage(string message, int level);
3. LogMessage(string filename, string message, int level)

As shown above, different parameters can be passed to this method as per convenience. I would suggest to use the third syntax.

Let’s see an example of this. I have created a simple list page and below is the code snippet of the page. I have called this List under MyCRM context by adding a tab.

class ProjectsList:ListPage
public ProjectsList()
: base(“Projects”, ” ProjectsList “, “ProjectsFilterBox”)
int sUserId = 0;
sUserId = CurrentUser.UserId;
LogMessage(“DotNetRoutineLogs”, “— Log for list page Start —“, 1);
LogMessage(“DotNetRoutineLogs”, “— Log important messages/errors here —“, 1);
this.ResultsGrid.Filter = “proj_assigneduserid=” + sUserId.ToString();
LogMessage(“DotNetRoutineLogs”, “— Log for list page End —“, 1);

Now, when your page runs, a log file with the same name as specified in the method will be created in the Logs folder of CRM directory. You can see in the below screenshot that, a log file named DotNetRoutineLogs is created.


You can use logging level by specifying level while writing the log. I have explained this with a simple example. This can be surely used in better way for complex implementations.

Now, as this log file gets created in Logs folder then, how user will access it? Below is the blog link where you will get to know how to configure logs.

How log files are maintained in Sage CRM

Isn’t it a pretty simple? Happy Coding..!!!

Also Read:

1. Boost Knowledge Base with Download links in Customer Portal
2. Managing Knowledge Base in the Self Service Portal
3. File Downloads in Self Service Portal
4. Integrate CRM Self Service Portal with Sage CRM
5. Identify the version in Sage CRM Cloud