public MonitoringLogEntry PopulateDefaultLogEntry() { MonitoringLogEntry logEntry = new MonitoringLogEntry(); logEntry.EventId = MonitoringLogEntryDefaults.EventId; logEntry.Priority = MonitoringLogEntryDefaults.Priority; logEntry.ExtendedActivityId = AppContext.Current.ActivityID; logEntry.UserName = AppContext.Current.UserName; logEntry.UserID = AppContext.Current.UserID; logEntry.IpAddress = AppContext.Current.IPAddress; logEntry.UserRoles = AppContext.Current.UserRoles; logEntry.UserGraphicArea = AppContext.Current.GraphicArea; //logEntry.Organization = AppContext.Current.Organization; logEntry.Office = AppContext.Current.Office; return logEntry; }
public static void WriteLog(SecurityExceptionType type, string message) { MonitoringLogEntry logEntry = new MonitoringLogEntry(); logEntry.Categories.Add(type.ToString()); logEntry.ExtendedActivityId = AppContext.Current.ActivityID; logEntry.ModuleId = AppContext.Current.ModuleID; logEntry.FunctionId = AppContext.Current.FunctionID; logEntry.UserName = AppContext.Current.UserName; logEntry.UserID = AppContext.Current.UserID; logEntry.IpAddress = AppContext.Current.IPAddress; logEntry.UserRoles = AppContext.Current.UserRoles; logEntry.UserGraphicArea = AppContext.Current.GraphicArea; //logEntry.Organization = AppContext.Current.Organization; logEntry.Office = AppContext.Current.Office; logEntry.Message = message; logEntry.EventId = 0; logEntry.Priority = -1; logEntry.Severity = TraceEventType.Warning; logEntry.Title = type.ToString() + " Error"; Logger.Write(logEntry); }
public static void WriteLogWhenLoginSuccessful(long? startTrick, long? endTrick, long elapsedMilliseconds) { MonitoringPopulateLogEntry utility = new MonitoringPopulateLogEntry(); Guid id = Guid.NewGuid(); MonitoringLogEntry entry = new MonitoringLogEntry(); entry.TracingStartTicks = startTrick; entry.TracingEndTicks = endTrick; decimal secondsElapsed = utility.GetSecondsElapsed(elapsedMilliseconds); entry.SecondsElapsed = secondsElapsed; entry.MethodName = "HiiP.Framework.Security.AccessControl.Authentication.Authenticate"; entry.ParameterValues = "void"; entry.ExtendedActivityId = id.ToString(); entry.UserID = AppContext.Current.UserID; entry.UserName = AppContext.Current.UserName; entry.UserRoles = AppContext.Current.UserRoles; entry.UserGraphicArea = AppContext.Current.GraphicArea; //entry.Organization = AppContext.Current.Organization; entry.Office = AppContext.Current.Office; entry.IpAddress =AppContext.Current.IPAddress; entry.Categories.Add("Trace"); entry.Title = "Login Successful"; entry.Message = "Login Successful"; entry.ModuleId = "Login"; entry.FunctionId = "Login"; entry.Severity = TraceEventType.Information; entry.Component = ComponentType.BusinessService; if (Logger.ShouldLog(entry)) { Logger.Write(entry); } }
private void PopulateStoredProcedueDetail(MonitoringLogEntry logEntry, EventArgs e,string[] rows) { LogWriter logWriter = Logger.Writer; if ((logEntry.Flag & FilterFlag.InstrumentationFlag) != FilterFlag.InstrumentationFlag) { logWriter.Write(logEntry); return; } RowUpdatingEventArgs updatingEvent = e as RowUpdatingEventArgs; if (updatingEvent != null) { StringBuilder builder = new StringBuilder(); builder.AppendLine("This is for row updating"); BuildCommandInfo(builder, updatingEvent.Command); if (updatingEvent.Errors != null) { builder.AppendLine("Row errors: " + updatingEvent.Errors.Message); } logEntry.ParameterValues = builder.ToString() + ((rows.Length == 0) ? "" : rows[0]); PopulatePostLogEntry(logEntry); logWriter.Write(logEntry); } else { RowUpdatedEventArgs updatedEvent = e as RowUpdatedEventArgs; if (updatedEvent != null) { StringBuilder builder = new StringBuilder(); builder.AppendLine("This is for row updated"); BuildCommandInfo(builder, updatedEvent.Command); if (updatedEvent.Errors != null) { builder.AppendLine("Row errors: " + updatedEvent.Errors.Message); } if (updatedEvent.StatementType != StatementType.Batch) { logEntry.ParameterValues = builder.ToString() + ((rows.Length == 0) ? "" : rows[0]); PopulatePostLogEntry(logEntry); logWriter.Write(logEntry); } else { builder.AppendLine("Batch row count :" + updatedEvent.RowCount); if (rows != null) { foreach (string batchRow in rows) { logEntry.ParameterValues = builder.ToString() + batchRow; PopulatePostLogEntry(logEntry); logWriter.Write(logEntry); } } } } } }
private void PopulatePreLogEntry(MonitoringLogEntry logEntry) { logEntry.Severity = TraceEventType.Start; logEntry.Title = "TracerEnter"; }
private void PopulatePostLogEntry(MonitoringLogEntry logEntry) { logEntry.Severity = TraceEventType.Stop; logEntry.Title = "TracerExit"; }
private MonitoringLogEntry CreateStandardEntry() { MonitoringLogEntry log = new MonitoringLogEntry(); log.Component = ComponentType.Screen; log.Severity = TraceEventType.Information; log.Categories.Add(LoggingCategories.Monitoring); log.UserID = AppContext.Current.UserID; log.UserName = AppContext.Current.UserName; return log; }
protected virtual void WriteToLog(string logMessage, IDictionary exceptionData, string InstanceId) { MonitoringLogEntry logEntry = new MonitoringLogEntry(); logEntry.InstanceID = InstanceId; logEntry.ExtendedActivityId= AppContext.Current.ActivityID; logEntry.ModuleId = AppContext.Current.ModuleID; logEntry.FunctionId = AppContext.Current.FunctionID; logEntry.UserName = AppContext.Current.UserName; logEntry.IpAddress = AppContext.Current.IPAddress; logEntry.UserRoles = AppContext.Current.UserRoles; logEntry.UserGraphicArea = AppContext.Current.GraphicArea; //logEntry.Organization = AppContext.Current.Organization; logEntry.Office = AppContext.Current.Office; logEntry.Categories.Add(logCategory); logEntry.EventId = eventId; logEntry.Title = defaultTitle; logEntry.Priority = minimumPriority; logEntry.Severity = severity; logEntry.Component = component; logEntry.Message = logMessage; foreach (DictionaryEntry dataEntry in exceptionData) { var key = dataEntry.Key as string; if (key==null) { continue; } logEntry.ExtendedProperties.Add(key, dataEntry.Value); } this.logWriter.Write(logEntry); }
/// <summary> /// Executes the WriteLog stored procedure /// </summary> /// <param name="logEntry">The MyLogEntry to store in the database.</param> /// <param name="database">The database.</param> /// <returns>An integer for the MyLogEntry Id</returns> private int ExecuteWriteLogStoredProcedure(MonitoringLogEntry logEntry, Database database) { try { DbCommand commmand = database.GetStoredProcCommand(WriteLogStoredProcName); database.AddInParameter(commmand, "p_app_name", DbType.String, _applicationName); database.AddInParameter(commmand, "p_event_id", DbType.Int32, logEntry.EventId); database.AddInParameter(commmand, "p_priority", DbType.Int32, logEntry.Priority); database.AddInParameter(commmand, "p_severity", DbType.String, logEntry.Severity.ToString()); database.AddInParameter(commmand, "p_title", DbType.String, logEntry.Title); database.AddInParameter(commmand, "p_log_time", DbType.DateTime, logEntry.TimeStamp.ToLocalTime()); database.AddInParameter(commmand, "p_machine_name", DbType.String, logEntry.MachineName); database.AddInParameter(commmand, "p_app_domain_name", DbType.String, logEntry.AppDomainName); database.AddInParameter(commmand, "p_process_id", DbType.String, logEntry.ProcessId); database.AddInParameter(commmand, "p_process_name", DbType.String, logEntry.ProcessName); database.AddInParameter(commmand, "p_thread_name", DbType.String, logEntry.ManagedThreadName); database.AddInParameter(commmand, "p_win32_thread_id", DbType.String, logEntry.Win32ThreadId); database.AddInParameter(commmand, "p_message", DbType.String, logEntry.Message); database.AddInParameter(commmand, "p_method_name", DbType.String, logEntry.MethodName); database.AddInParameter(commmand, "p_activity_id", DbType.String, logEntry.ExtendedActivityId); database.AddInParameter(commmand, "p_tracing_start_ticks", DbType.String, logEntry.TracingStartTicks); database.AddInParameter(commmand, "p_tracing_end_ticks", DbType.String, logEntry.TracingEndTicks); database.AddInParameter(commmand, "p_seconds_elapsed", DbType.Decimal, logEntry.SecondsElapsed); database.AddInParameter(commmand, "p_user_name", DbType.String, logEntry.UserName); database.AddInParameter(commmand, "p_ip_address", DbType.String, logEntry.IpAddress); database.AddInParameter(commmand, "p_user_roles", DbType.String, logEntry.UserRoles); database.AddInParameter(commmand, "p_user_graphic_area", DbType.String, logEntry.UserGraphicArea); database.AddInParameter(commmand, "p_organization", DbType.String, null); database.AddInParameter(commmand, "p_office", DbType.String, logEntry.Office); database.AddInParameter(commmand, "p_module_id", DbType.String, logEntry.ModuleId); database.AddInParameter(commmand, "p_function_id", DbType.String, logEntry.FunctionId); database.AddInParameter(commmand, "p_component", DbType.String, logEntry.Component.ToString()); database.AddInParameter(commmand, "p_parameter_values", DbType.String, logEntry.ParameterValues); database.AddInParameter(commmand, "p_flag", DbType.Int32, logEntry.Flag); database.AddInParameter(commmand, "p_instance_id", DbType.String, logEntry.InstanceID); database.AddInParameter(commmand, "p_return_value", DbType.String, logEntry.ReturnValue); if (Formatter != null) { database.AddInParameter(commmand, "p_formatted_message", DbType.String, Formatter.Format(logEntry)); } else { database.AddInParameter(commmand, "p_formatted_message", DbType.String, logEntry.Message); } database.AddOutParameter(commmand, "p_log_id", DbType.Int32, 9); database.ExecuteNonQuery(commmand); int logId = (int)database.GetParameterValue(commmand, "p_log_id"); return logId; } catch (DbException ex) { ExceptionHelper.HandleCommonDbException(ex); throw; } }
/// <summary> /// Writes a predefined messgae. /// </summary> /// <param name="message">The log message.</param> public override void Write(string message) { MonitoringLogEntry logEntry = new MonitoringLogEntry(); logEntry.EventId = 0; logEntry.Priority = 5; logEntry.Severity = TraceEventType.Information; logEntry.Title = string.Empty; logEntry.TimeStamp = DateTime.UtcNow; logEntry.Message = message; ExecuteWriteLogStoredProcedure(logEntry, _database); }