public BasicServiceResult logMethod( string name, string parameters, DateTime callDate, bool success, Guid sessionGuid, double duration, bool testCall, string api, string returnValue, string exceptionSource, string exceptionMessage, string exceptionStackTrace, string exceptionTargetSite, string friendlyMessage, string developerMessage) { //under the case that there was no error or exception //this will still be empty guids Guid errorGuid = Guid.Empty; Guid exceptionGuid = Guid.Empty; //get that service error message if it exists if (friendlyMessage.isNotNullOrEmpty() || developerMessage.isNotNullOrEmpty()) { errorGuid = Guid.NewGuid(); var mem = new BL.MethodErrorMessage(errorGuid, "2", friendlyMessage, developerMessage, callDate); var sr = mem.save(); if (!sr.wasSuccess()) { return(new BasicServiceResult(sr)); } } //get that exception deets if they exist if (exceptionMessage.isNotNullOrEmpty()) { var mle = new BL.MethodLogException(Guid.NewGuid(), "2", exceptionSource, exceptionMessage, exceptionStackTrace, exceptionTargetSite, callDate); exceptionGuid = mle.guid; var sr = mle.save(); if (!sr.wasSuccess()) { return(new BasicServiceResult(sr)); } } var ml = new BL.MethodLog(name, parameters, callDate, success, sessionGuid, errorGuid, exceptionGuid, duration, testCall, api, returnValue); var saveResult = ml.save(); if (!saveResult.wasSuccess()) { return(new BasicServiceResult(saveResult)); } return(BasicServiceResult.NoError); }
/// <summary> /// Log the Methods execution results details. /// </summary> /// <param name="args">Advice arguments.</param> /// <param name="success">Result of the method operation.</param> private void LogMethod(MethodExecutionArgs args, bool success) { var endTime = DateTime.UtcNow; Guid errorGuid = Guid.Empty; Guid exceptionGuid = Guid.Empty; string sessionId = null; ServiceError error = null; string returnValues; extractReturnValue(args, out returnValues); // Save the MB error if returning one to the caller Object returnValue = args.ReturnValue; if (returnValue is IServiceResult) { error = ((IServiceResult)returnValue).error; if (error.hadException) { var m = new BL.MethodLogException(error.exception, DateTime.UtcNow); exceptionGuid = m.guid; m.save(); } if (!error.success) { var mle = new BL.MethodErrorMessage(Guid.NewGuid(), "2", error.friendlyErrorMsg, error.developerErrorMsg, DateTime.UtcNow); errorGuid = mle.guid; mle.save(); } } StringBuilder stringBuilder = new StringBuilder(); var jsonSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); int i; // Get the list of all arguments. for (i = 0; i < args.Arguments.Count; i++) { if (parameters[i].Name.Equals("sessionid", StringComparison.InvariantCultureIgnoreCase)) { object sessionValue = args.Arguments.GetArgument(i); if (sessionValue != null) { sessionId = sessionValue.ToString(); } } else { if (i > 0) { stringBuilder.Append(", "); } stringBuilder.Append(parameters[i].Name).Append("="); if (parameters[i].Name.ToLower().Contains("password")) { stringBuilder.Append("[redacted]"); } else { object arg = args.Arguments.GetArgument(i); stringBuilder.Append(arg ?? "null"); if (arg != null) { Type argType = args.Arguments.GetArgument(i).GetType(); if (!argType.IsPrimitive && !argType.Equals(typeof(string)) && argType.IsSerializable) { stringBuilder.Append(":").Append(jsonSerializer.Serialize(args.Arguments.GetArgument(i))); } } } } } var ml = new BL.MethodLog(this.methodName, stringBuilder.ToString(), startTime, errorGuid.Equals(Guid.Empty), Guid.Empty, exceptionGuid, errorGuid, (endTime - startTime).TotalMilliseconds, false, "LogServ", returnValues); ml.save(); }