/// <summary> /// The log. /// </summary> /// <param name="logger"> /// The logger. /// </param> /// <param name="userId"> /// The user id. /// </param> /// <param name="source"> /// The source. /// </param> /// <param name="exception"> /// The exception. /// </param> /// <param name="eventType"> /// The event type. /// </param> public static void Log( [NotNull] this ILogger logger, [CanBeNull] int?userId, [CanBeNull] object source, [NotNull] Exception exception, EventLogTypes eventType = EventLogTypes.Error) { CodeContracts.VerifyNotNull(logger, "logger"); string username = null; if (userId.HasValue && userId > 0) { username = YafContext.Current.Get <IUserDisplayName>().GetName(userId.Value); } var sourceDescription = "unknown"; if (source is Type) { sourceDescription = source.GetType().FullName; } else if (source != null) { sourceDescription = source.ToString().Truncate(50); } logger.Log( "Exception at URL: {0}".FormatWith(YafContext.Current.Get <HttpRequestBase>().Url.ToString()), eventType, username, sourceDescription, exception); }
public static void UseFile(String filename) { if (filename == null) throw new ArgumentNullException("filename"); Type = EventLogTypes.File; m_filename = filename; m_event_log = null; }
/// <summary> /// The is log type enabled. /// </summary> /// <param name="type">The type.</param> /// <returns> /// The <see cref="bool" />. /// </returns> public bool IsLogTypeEnabled(EventLogTypes type) { if (this._eventLogTypeLookup == null) { // create it... this.InitLookup(); } return(this._eventLogTypeLookup.ContainsKey(type) && this._eventLogTypeLookup[type]); }
public async Task AddStudentEvent(int studentId, EventLogTypes eventType, string remoteIp) { EventLogModel log = new EventLogModel() { Date = DateTime.Now, StudentId = studentId, Type = (int)eventType, IPAddress = remoteIp }; await AddStudentEvent(log); }
/// <summary> /// The create. /// </summary> /// <param name="repository"> /// The repository. /// </param> /// <param name="userID"> /// The user id. /// </param> /// <param name="source"> /// The source. /// </param> /// <param name="description"> /// The description. /// </param> /// <param name="type"> /// The type. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> public static int Create(this IRepository<EventLog> repository, int? userID, object source, string description, EventLogTypes logType = EventLogTypes.Information) { CodeContracts.VerifyNotNull(repository, "repository"); var returnValue = (int) repository.DbFunction.Scalar.eventlog_create( UserID: userID, Source: source.GetType().ToString(), Description: description, Type: logType.ToInt(), UTCTIMESTAMP: DateTime.UtcNow); repository.FireNew(); return returnValue; }
public bool RegisterEvent(EventLogTypes eventLogTypes, string message, string source, string messageException, string userName) { var eventLog = new EventLog() { EventLogTypeId = eventLogTypes, Source = source, Message = message, MessageException = messageException, UserName = userName, Date = DateTime.UtcNow }; //UNDONE: Write to file return(true); }
public async Task <bool> RegisterEventAsync(EventLogTypes eventLogTypes, string message, string source, string messageException, string userName) { EventLog eventLog = new EventLog() { EventLogTypeId = eventLogTypes, Source = source, Message = message, MessageException = messageException, UserName = userName, Date = DateTime.UtcNow }; _ctx.EventLogs.Add(eventLog); int c = await _ctx.SaveChangesAsync(); return(c == 0 ? false : true); }
/// <summary> /// The log. /// </summary> /// <param name="logger"> /// The logger. /// </param> /// <param name="username"> /// The username. /// </param> /// <param name="source"> /// The source. /// </param> /// <param name="description"> /// The description. /// </param> /// <param name="eventType"> /// The event type. /// </param> public static void Log( [NotNull] this ILogger logger, [CanBeNull] string username, [CanBeNull] object source, [NotNull] string description, [NotNull] EventLogTypes eventType = EventLogTypes.Error) { CodeContracts.VerifyNotNull(logger, "logger"); var sourceDescription = "unknown"; if (source is Type) { sourceDescription = source.GetType().FullName; } else if (source != null) { sourceDescription = source.ToString(); } logger.Log(description, eventType, username, sourceDescription); }
/// <summary> /// The log. /// </summary> /// <param name="logger"> /// The logger. /// </param> /// <param name="userName"> /// The user Name. /// </param> /// <param name="source"> /// The source. /// </param> /// <param name="exception"> /// The exception. /// </param> /// <param name="eventType"> /// The event type. /// </param> public static void Log( [NotNull] this ILogger logger, [CanBeNull] string userName, [CanBeNull] object source, [NotNull] Exception exception, EventLogTypes eventType = EventLogTypes.Error) { CodeContracts.VerifyNotNull(logger, "logger"); var sourceDescription = "unknown"; if (source is Type) { sourceDescription = source.GetType().FullName; } else if (source != null) { sourceDescription = source.ToString().Truncate(50); } string message; try { message = $"Exception at URL: {BoardContext.Current.Get<HttpRequestBase>().Url}"; } catch (Exception) { message = "Exception"; } logger.Log( message, eventType, userName, sourceDescription, exception); }
/// <summary> /// The log. /// </summary> /// <param name="logger"> /// The logger. /// </param> /// <param name="userId"> /// The user id. /// </param> /// <param name="source"> /// The source. /// </param> /// <param name="description"> /// The description. /// </param> /// <param name="eventType"> /// The event type. /// </param> public static void Log( [NotNull] this ILogger logger, int userId, [CanBeNull] object source, [NotNull] string description, EventLogTypes eventType = EventLogTypes.Error) { CodeContracts.VerifyNotNull(logger, "logger"); var username = YafContext.Current.Get <IUserDisplayName>().GetName(userId); var sourceDescription = "unknown"; if (source is Type) { sourceDescription = source.GetType().FullName; } else if (source != null) { sourceDescription = source.ToString().Truncate(50); } logger.Log(description, eventType, username.IsNotSet() ? "N/A" : username, sourceDescription); }
/// <summary> /// The log. /// </summary> /// <param name="logger"> /// The logger. /// </param> /// <param name="userId"> /// The user id. /// </param> /// <param name="source"> /// The source. /// </param> /// <param name="description"> /// The description. /// </param> /// <param name="eventType"> /// The event type. /// </param> public static void Log( [NotNull] this ILogger logger, int userId, [CanBeNull] object source, [NotNull] string description, EventLogTypes eventType = EventLogTypes.Error) { CodeContracts.VerifyNotNull(logger, "logger"); var username = YafContext.Current.Get<IUserDisplayName>().GetName(userId); var sourceDescription = "unknown"; if (source is Type) { sourceDescription = source.GetType().FullName; } else if (source != null) { sourceDescription = source.ToString().Truncate(50); } logger.Log(description, eventType, username.IsNotSet() ? "N/A" : username, sourceDescription); }
/// <summary> /// The create. /// </summary> /// <param name="repository"> /// The repository. /// </param> /// <param name="userID"> /// The user id. /// </param> /// <param name="source"> /// The source. /// </param> /// <param name="description"> /// The description. /// </param> /// <param name="type"> /// The type. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> public static int Create(this IRepository <EventLog> repository, int?userID, object source, string description, EventLogTypes logType = EventLogTypes.Information) { CodeContracts.VerifyNotNull(repository, "repository"); var returnValue = (int) repository.DbFunction.Scalar.eventlog_create( UserID: userID, Source: source.GetType().ToString(), Description: description, Type: logType.ToInt(), UTCTIMESTAMP: DateTime.UtcNow); repository.FireNew(); return(returnValue); }
public static void UseStandardError() { Type = EventLogTypes.StandardError; m_event_log = null; }
/// <summary> /// The log. /// </summary> /// <param name="logger"> /// The logger. /// </param> /// <param name="userId"> /// The user id. /// </param> /// <param name="source"> /// The source. /// </param> /// <param name="exception"> /// The exception. /// </param> /// <param name="eventType"> /// The event type. /// </param> public static void Log( [NotNull] this ILogger logger, [CanBeNull] int? userId, [CanBeNull] object source, [NotNull] Exception exception, EventLogTypes eventType = EventLogTypes.Error) { CodeContracts.VerifyNotNull(logger, "logger"); string username = null; if (userId.HasValue && userId > 0) { username = YafContext.Current.Get<IUserDisplayName>().GetName(userId.Value); } var sourceDescription = "unknown"; if (source is Type) { sourceDescription = source.GetType().FullName; } else if (source != null) { sourceDescription = source.ToString().Truncate(50); } logger.Log("Exception", eventType, username, sourceDescription, exception); }
/// <summary> /// The log. /// </summary> /// <param name="message"> /// The message. /// </param> /// <param name="eventType"> /// The event type. /// </param> /// <param name="username"> /// The username. /// </param> /// <param name="source"> /// The source. /// </param> /// <param name="exception"> /// The exception. /// </param> public void Log( string message, EventLogTypes eventType = EventLogTypes.Error, string username = null, string source = null, Exception exception = null) { if (!this.IsLogTypeEnabled(eventType)) { return; } var exceptionDescription = string.Empty; if (exception != null) { exceptionDescription = exception.ToString(); } var formattedDescription = message + "\r\n" + exceptionDescription; switch (eventType) { case EventLogTypes.Debug: Debug.WriteLine(formattedDescription, source); break; case EventLogTypes.Trace: Trace.TraceInformation(formattedDescription); if (exception != null) { Trace.TraceError(exception.ToString()); } break; default: { if (source.IsNotSet()) { if (this.Type != null) { source = this.Type.FullName.Length > 50 ? this.Type.FullName.Truncate(47) : this.Type.FullName; } else { source = string.Empty; } } var log = new EventLog { EventType = eventType, UserName = username, Description = formattedDescription, Source = source, EventTime = DateTime.UtcNow }; this.EventLogRepository.Insert(log); } break; } }
public static void UseStandardOutput() { Type = EventLogTypes.StandardOutput; m_event_log = null; }
/// <summary> /// The log. /// </summary> /// <param name="message"> /// The message. /// </param> /// <param name="eventType"> /// The event type. /// </param> /// <param name="username"> /// The username. /// </param> /// <param name="source"> /// The source. /// </param> /// <param name="exception"> /// The exception. /// </param> public void Log( string message, EventLogTypes eventType = EventLogTypes.Error, string username = null, string source = null, Exception exception = null) { if (!this.IsLogTypeEnabled(eventType)) { return; } var exceptionDescription = string.Empty; if (exception != null) { exceptionDescription = exception.ToString(); } var formattedDescription = HttpContext.Current != null ? "{0} (URL:'{1}')\r\n{2}".FormatWith( message, HttpContext.Current.Request.Url, exceptionDescription) : "{0}\r\n{1}".FormatWith(message, exceptionDescription); if (source.IsNotSet()) { if (this.Type != null) { source = this.Type.FullName.Length > 50 ? this.Type.FullName.Truncate(47) : this.Type.FullName; } else { source = string.Empty; } } switch (eventType) { case EventLogTypes.Debug: Debug.WriteLine(formattedDescription, source); break; case EventLogTypes.Trace: Trace.TraceInformation(formattedDescription); if (exception != null) { Trace.TraceError(exception.ToString()); } break; case EventLogTypes.Information: if (YafContext.Current.Get<YafBoardSettings>().LogInformation) { this.EventLogRepository.Insert( new EventLog { EventType = eventType, UserName = username, Description = formattedDescription, Source = source, EventTime = DateTime.UtcNow }); } break; case EventLogTypes.Warning: if (YafContext.Current.Get<YafBoardSettings>().LogWarning) { this.EventLogRepository.Insert( new EventLog { EventType = eventType, UserName = username, Description = formattedDescription, Source = source, EventTime = DateTime.UtcNow }); } break; case EventLogTypes.Error: if (YafContext.Current.Get<YafBoardSettings>().LogError) { this.EventLogRepository.Insert( new EventLog { EventType = eventType, UserName = username, Description = formattedDescription, Source = source, EventTime = DateTime.UtcNow }); } break; default: { var log = new EventLog { EventType = eventType, UserName = username, Description = formattedDescription, Source = source, EventTime = DateTime.UtcNow }; this.EventLogRepository.Insert(log); } break; } }
/// <summary> /// The log. /// </summary> /// <param name="message"> /// The message. /// </param> /// <param name="logTypes"> /// The log types. /// </param> private void Log([NotNull] string message, EventLogTypes logTypes) { string typeName = "Unknown"; if (this.Type != null) { typeName = this.Type.FullName.Length > 50 ? this.Type.FullName.Substring(0, 50) : this.Type.FullName; } // TODO: come up with userid if the database is available. CommonDb.eventlog_create(YafContext.Current.PageModuleID, null, typeName, message.IsNotSet() ? string.Empty : message, logTypes); }
/// <summary> /// The log. /// </summary> /// <param name="userId"> /// The userId. /// </param> /// <param name="message"> /// The message. /// </param> /// <param name="logTypes"> /// The log types. /// </param> private void Log(int userId, [NotNull] string message, EventLogTypes logTypes) { string typeName = "Unknown"; if (this.Type != null) { typeName = this.Type.FullName; } // TODO: come up with userid if the database is available. CommonDb.eventlog_create(YafContext.Current.PageModuleID, userId, typeName, message, logTypes); }
/// <summary> /// The log. /// </summary> /// <param name="message"> /// The message. /// </param> /// <param name="eventType"> /// The event type. /// </param> /// <param name="userId"> /// The user Id. /// </param> /// <param name="source"> /// The source. /// </param> /// <param name="exception"> /// The exception. /// </param> public void Log( [NotNull] string message, [NotNull] EventLogTypes eventType = EventLogTypes.Error, [CanBeNull] int?userId = null, [CanBeNull] string source = null, [CanBeNull] Exception exception = null) { userId ??= BoardContext.Current.User.ID; if (!this.IsLogTypeEnabled(eventType)) { return; } var exceptionDescription = string.Empty; if (exception != null) { exceptionDescription = exception.ToString(); } var formattedDescription = HttpContext.Current != null ? $"{message} (URL:'{HttpContext.Current.Request.Url}')\r\n{exceptionDescription}" : $"{message}\r\n{exceptionDescription}"; if (source.IsNotSet()) { if (this.Type != null) { source = this.Type.FullName.Length > 50 ? this.Type.FullName.Truncate(47) : this.Type.FullName; } else { source = string.Empty; } } switch (eventType) { case EventLogTypes.Debug: Debug.WriteLine(formattedDescription, source); break; case EventLogTypes.Trace: Trace.TraceInformation(formattedDescription); if (exception != null) { Trace.TraceError(exception.ToString()); } break; case EventLogTypes.Information: if (this.Get <BoardSettings>().LogInformation) { this.EventLogRepository.Insert( new EventLog { EventType = eventType, UserID = userId, Description = formattedDescription, Source = source, EventTime = DateTime.UtcNow }); } break; case EventLogTypes.Warning: if (this.Get <BoardSettings>().LogWarning) { this.EventLogRepository.Insert( new EventLog { EventType = eventType, UserID = userId, Description = formattedDescription, Source = source, EventTime = DateTime.UtcNow }); } break; case EventLogTypes.Error: if (this.Get <BoardSettings>().LogError) { this.EventLogRepository.Insert( new EventLog { EventType = eventType, UserID = userId, Description = formattedDescription, Source = source, EventTime = DateTime.UtcNow }); } break; default: { var log = new EventLog { EventType = eventType, UserID = userId, Description = formattedDescription, Source = source, EventTime = DateTime.UtcNow }; this.EventLogRepository.Insert(log); } break; } }
/// <summary> /// The eventlog_create. /// </summary> /// <param name="mid"> /// The mid. /// </param> /// <param name="userId"> /// The user id. /// </param> /// <param name="source"> /// The source. /// </param> /// <param name="description"> /// The description. /// </param> /// <param name="type"> /// The type. /// </param> public static void eventlog_create( int? mid, object userId, object source, object description, EventLogTypes type) { try { source = source.GetType().ToString(); } catch { } if (description is Exception) { var ex = (Exception)description; description = ex.Message + "\r\n" + ex.Source + "\r\n" + ex.StackTrace; } // TODO: Implement the object existance as it throws errors during install if (GetIsForumInstalled(mid)) { #if !DEBUG try{ #endif using (var sc = new VzfSqlCommand(mid)) { sc.Parameters.Add(sc.CreateParameter(DbType.Int32, "i_UserID", userId)); sc.Parameters.Add(sc.CreateParameter(DbType.String, "i_Source", source)); sc.Parameters.Add(sc.CreateParameter(DbType.String, "i_Description", description)); sc.Parameters.Add(sc.CreateParameter(DbType.Int32, "i_Type", type.ToInt())); sc.Parameters.Add(sc.CreateParameter(DbType.DateTime, "i_UTCTIMESTAMP", DateTime.UtcNow)); sc.CommandText.AppendObjectQuery("eventlog_create", mid); sc.ExecuteNonQuery(CommandType.StoredProcedure); } #if !DEBUG } catch(Exception e) { throw; } #endif } }
/// <summary> /// The log. /// </summary> /// <param name="message"> /// The message. /// </param> /// <param name="logTypes"> /// The log types. /// </param> private void Log([NotNull] string message, EventLogTypes logTypes) { string typeName = "Unknown"; if (this.Type != null) { typeName = this.Type.FullName; } // TODO: come up with userid if the database is available. LegacyDb.eventlog_create(null, typeName, message, logTypes); }
/// <summary> /// The is log type enabled. /// </summary> /// <param name="type">The type.</param> /// <returns> /// The <see cref="bool" />. /// </returns> public bool IsLogTypeEnabled(EventLogTypes type) { if (this._eventLogTypeLookup == null) { // create it... this.InitLookup(); } return this._eventLogTypeLookup.ContainsKey(type) && this._eventLogTypeLookup[type]; }
public static void UseEventLog(EventLog event_log) { if (event_log == null) throw new ArgumentNullException("event_log"); Type = EventLogTypes.Windows; m_event_log = event_log; }