public void PopulateLogEntryForCallHandler(IMethodInvocation input, //List<string> categories, //bool includeParameters, bool includeCallStack, IMethodReturn result, long? tracingStartTicks, long? tracingEndTicks, long elapsedMilliseconds, string messageFormat, string moduleId, string functionId, ComponentType component) { MonitoringLogEntry logEntry = PopulateDefaultLogEntry(); using (BackgroundWorker worker = new BackgroundWorker()) { worker.DoWork += delegate(object oDoWork, DoWorkEventArgs eDoWork) { try { AppContext.SetToCallContext(AppContext.Current.ToDictionary()); CategoryFormatter formatter = new CategoryFormatter(input.MethodBase); logEntry = eDoWork.Argument as MonitoringLogEntry; //foreach (string category in categories) //{ // logEntry.Categories.Add(formatter.FormatCategory(category)); //} logEntry.Categories.Add(formatter.FormatCategory(LoggingCategories.Monitoring)); logEntry.Component = component; if (!Logger.ShouldLog(logEntry)) { return; } //When do the instrumentation log , we should log the parameter values information, otherwise not if ((logEntry.Flag & FilterFlag.InstrumentationFlag) == FilterFlag.InstrumentationFlag) { //if (includeParameters) { logEntry.ParameterValues = GenerateValuesInfo(input.Arguments, true); } } //if (includeCallStack) //{ // logEntry.CallStack = Environment.StackTrace; //} logEntry.TypeName = input.Target.GetType().FullName; logEntry.MethodName = string.Concat(input.MethodBase.DeclaringType.FullName, ".", input.MethodBase.Name); if (result == null) { PopulatePreLogEntry(logEntry); } else { PopulatePostLogEntry(logEntry); if ((logEntry.Flag & FilterFlag.InstrumentationFlag) == FilterFlag.InstrumentationFlag) { int depth = 0; object returnedValue = result.ReturnValue; logEntry.ReturnValue = GenerateValueInfo("ReturnValue", returnedValue, (returnedValue == null) ? null : returnedValue.GetType(), ref depth); } } logEntry.TracingStartTicks = tracingStartTicks; logEntry.TracingEndTicks = tracingEndTicks; logEntry.SecondsElapsed = GetSecondsElapsed(elapsedMilliseconds); logEntry.Message = string.Format(Resources.Culture, messageFormat, logEntry.ExtendedActivityId, logEntry.MethodName, logEntry.TracingEndTicks, logEntry.SecondsElapsed); logEntry.FunctionId = functionId; logEntry.ModuleId = moduleId; //if (result.ReturnValue != null && includeParameters) //{ // logEntry.ReturnValue = result.ReturnValue.ToString(); //} if (result != null && result.Exception != null) { logEntry.Exception = result.Exception.ToString(); } LogWriter logWriter = Logger.Writer; logWriter.Write(logEntry); } catch (Exception ex) { //Swallow exception, because it is logging should not impact the business function HiiPLoggingExceptionHandler handler = new HiiPLoggingExceptionHandler("Server Exception", 100, TraceEventType.Error, "Instrumtation logging of RowUpdated failed", 0, typeof(HiiPLoggingExceptionFormatter), ComponentType.StoredProcedure, Logger.Writer); handler.HandleException(ex, Guid.NewGuid()); } }; worker.RunWorkerAsync(logEntry); } }