public void LogEntry(MethodBase methodBase, object[] argumentValues, LogAttribute logAttribute) { ILog logger=null; if(logAttribute.LogType==null || logAttribute.LogType.Trim()==string.Empty) logger = _logFactory.Create(methodBase.DeclaringType.FullName); else logger = _logFactory.Create(logAttribute.LogType); if (ShouldLog(logger, logAttribute.EntryLevel, methodBase)) { string message = null; try { message = CreateInvocationLogString(methodBase, argumentValues, logAttribute); } catch (Exception exception) { message = string.Format("Failed to create invocation information for method: {0}.{1}{2}{3}",methodBase.DeclaringType.FullName,methodBase.Name, Environment.NewLine,exception.Message); } logger.Log(logAttribute.EntryLevel, message); } }
private string CreateInvocationLogString(MethodBase methodBase, object[] argumentValues, LogAttribute logAttribute) { StringBuilder sb = new StringBuilder(100); sb.AppendFormat("Called: {0}.{1}(", methodBase.DeclaringType.FullName, methodBase.Name); ParameterInfo[] parameters = methodBase.GetParameters(); string[] settings = null; if (logAttribute.SkipArguments != null && logAttribute.SkipArguments.Trim() != string.Empty) { settings = logAttribute.SkipArguments.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); } for (int i = 0; i < argumentValues.Length; i++) { object argument = argumentValues[i]; if (settings != null && settings.Contains(parameters[i].Name)) { sb.Append("[***],"); continue; } String argumentDescription = argument == null ? "null" : DumpObject(argument); sb.Append(argumentDescription).Append(","); } if (argumentValues.Length > 0) sb.Length--; sb.Append(")"); return sb.ToString(); }
private LogAttribute GetLoggingLevels(LogAttribute[] logAttributes) { LogAttribute currentLogAttribute = null; if (logAttributes != null && logAttributes.Count() > 0) currentLogAttribute = logAttributes[0]; foreach (LogAttribute logAttribute in logAttributes) { if (logAttribute.EntryLevel < currentLogAttribute.EntryLevel) { currentLogAttribute.EntryLevel = logAttribute.EntryLevel; } if (logAttribute.SuccessLevel < currentLogAttribute.SuccessLevel) { currentLogAttribute.SuccessLevel = logAttribute.SuccessLevel; } if (logAttribute.ExceptionLevel < currentLogAttribute.ExceptionLevel) { currentLogAttribute.ExceptionLevel = logAttribute.ExceptionLevel; } if (logAttribute.LogType != null && logAttribute.LogType.Trim() != string.Empty) { currentLogAttribute.LogType = logAttribute.LogType; } } return currentLogAttribute; }
private LogAttribute GetLoggingLevels(LogAttribute[] assemblyLogAttributes, LogAttribute[] classLogAttributes, LogAttribute[] methodLogAttributes) { LogAttribute logAttribute = null; if (methodLogAttributes.Length > 0) logAttribute = GetLoggingLevels(methodLogAttributes); else if (classLogAttributes.Length > 0) logAttribute = GetLoggingLevels(classLogAttributes); if (assemblyLogAttributes.Length > 0) logAttribute = GetLoggingLevels(assemblyLogAttributes); return logAttribute; }