Search code examples
eventsloggingdynamics-crmdynamics-crm-4crm

Microsoft CRM 4.0 Application Event Log Errors


wonder if someone can help. We have written a large number of callouts to be used with Microsoft CRM 4.0, these are all working fine and as expected. However we have noticed that every time there is a error with one of the callouts, the error message gets displayed to the user (as expected) but also gets put into the Application tab of the Windows Event Log. This isn't a massive problem, however it is filling the event log up somewhat! Is there a way to stop callout errors being posted to the event log?

Example of a callout, with error message displayed to user and event log:

public override PreCalloutReturnValue PreSetState(CalloutUserContext userContext, CalloutEntityContext entityContext, ref int newStateCode, ref int newStatusCode, ref string errorMessage)
            {
                try
                {
                    switch (entityContext.EntityTypeCode)
                    {
                        case Constants.TASK:

                            TaskCode taskCode = new TaskCode(ref _oServ, userContext.UserId);
                            task oTask = taskCode.GetTask(entityContext.InstanceId,
                                new string[]{"activityid", 
                                    "new_isdiscountauthorisation",  
                                    "new_discountstatus",
                                    "regardingobjectid",
                                    "isworkflowcreated"});

                            //*** only certain people able to update tasks (including owner) ***
                            if (!taskCode.PermitUpdate(userContext.UserId, entityContext.InstanceId))
                            {
                                errorMessage = "Only priveleged users and the owner of this task are permitted to update it";
                                return PreCalloutReturnValue.Abort;
                            }

                            break;

                            etc...................
                            etc...................



                    }
                }
                catch (Exception ex) { Utilities.LogError(ex, userContext.UserId); }

                return base.PreSetState(userContext, entityContext, ref newStateCode, ref newStatusCode, ref errorMessage);
            } 

Solution

  • Two Quick Things:

    • Event viewer automatically drops older events, and that maximum amount of events can be set in the event viewer by right clicking the log and selecting properties. So the amount of events shouldn't matter terribly considering it will just drop the old ones.

    • You probably shouldn't be getting errors in these callouts/plugins to begin with. Generally, you should be preventing users from initiating an action they are not allowed to do. If you purposefully want to not allow users to update a task, that might be something I would handle conditionally in the form code (checking permissions in javascript and making fields read only). I also understand you're giving an example so I might not understand the extent of the issue.

    I don't know of any specific way to prevent errors from writing to the log, and that strikes me as a fairly dangerous practice since you might miss something very important. You might try picking common errors and filtering them out?