public static void AddLogMessage(SqlLogRecord logRecord) { if (_sqlLogRecordEvent != null) { _sqlLogRecordEvent(logRecord); } }
private static void LogExceptionInThread(object threadInfoObject) { var infoLogCommand = (ThreadInfoLogCommand)threadInfoObject; MethodBase methodBase = infoLogCommand.StackFrame.GetMethod(); string methodBody = GetMethodBody(methodBase); string exceptionText = infoLogCommand.Exception == null ? string.Empty : infoLogCommand.Exception.Message + infoLogCommand.Exception.InnerException; SqlLogRecord sqlLogRecord = new SqlLogRecord { CommandText = exceptionText, Created = DateTime.Now.ToString(), MethodName = methodBase.Name, MethodBody = methodBody, ClassName = methodBase.DeclaringType.FullName, QueryMiliseconds = infoLogCommand.ElapsedMilliseconds, ResultRowsCount = infoLogCommand.ResultRowsCount, StackTrace = infoLogCommand.StackTraceSnippet }; if (IsSendToNetwork) { var queryCommand = new QueryCommand { CommandText = exceptionText, Created = DateTime.Now.ToString(), MethodName = methodBase.Name, MethodBody = methodBody, ClassName = methodBase.DeclaringType.FullName, QueryMiliseconds = infoLogCommand.ElapsedMilliseconds, ResultRowsCount = infoLogCommand.ResultRowsCount, StackTrace = infoLogCommand.StackTraceSnippet }; CommandSender.SendQueryCommand(queryCommand); } Nlogger.AddLogMessage(sqlLogRecord); Nlogger.AddLogMessage(string.Format("\r\n Exception {0}; \r\n Method Name {1}; \r\n Class Name {2}; \r\n Elapsed Miliseconds {3}", exceptionText, methodBase.Name, methodBase.DeclaringType.FullName, infoLogCommand.ElapsedMilliseconds)); }
private static void WriteMessageInThread(object threadInfoObject) { var infoLogCommand = (ThreadInfoLogCommand)threadInfoObject; MethodBase methodBase = infoLogCommand.StackFrame.GetMethod(); string methodBody = GetMethodBody(methodBase); SqlLogRecord sqlLogRecord = new SqlLogRecord { CommandText = infoLogCommand.Message, Created = DateTime.Now.ToString(), MethodName = methodBase.Name, MethodBody = methodBody, ClassName = methodBase.DeclaringType.FullName, QueryMiliseconds = 0, ResultRowsCount = 0, StackTrace = infoLogCommand.StackTraceSnippet }; if (IsSendToNetwork) { var queryCommand = new QueryCommand { CommandText = sqlLogRecord.CommandText, Created = sqlLogRecord.Created, MethodName = sqlLogRecord.MethodName, MethodBody = sqlLogRecord.MethodBody, ClassName = sqlLogRecord.ClassName, QueryMiliseconds = 0, ResultRowsCount = 0, StackTrace = sqlLogRecord.StackTrace }; CommandSender.SendQueryCommand(queryCommand); } Nlogger.AddLogMessage(sqlLogRecord); Nlogger.AddLogMessage(string.Format("\r\n Message: {0};\r\n Method Name: {1};\r\n Class Name: {2}", infoLogCommand.Message, methodBase.Name, methodBase.DeclaringType.FullName)); }