Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
 public static void UseFile(String filename)
 {
     if (filename == null) throw new ArgumentNullException("filename");
     Type = EventLogTypes.File;
     m_filename = filename;
     m_event_log = null;
 }
Ejemplo n.º 3
0
        /// <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]);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        /// <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;
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        /// <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);
        }
Ejemplo n.º 9
0
        /// <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);
        }
Ejemplo n.º 10
0
        /// <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);
        }
Ejemplo n.º 11
0
        /// <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);
        }
Ejemplo n.º 12
0
        /// <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);
        }
Ejemplo n.º 13
0
 public static void UseStandardError()
 {
     Type = EventLogTypes.StandardError;
     m_event_log = null;
 }
Ejemplo n.º 14
0
        /// <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);
        }
Ejemplo n.º 15
0
        /// <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;
            }
        }
Ejemplo n.º 16
0
 public static void UseStandardOutput()
 {
     Type = EventLogTypes.StandardOutput;
     m_event_log = null;
 }
Ejemplo n.º 17
0
        /// <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;
            }
        }
Ejemplo n.º 18
0
    /// <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);
    }
Ejemplo n.º 19
0
      /// <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);
    }
Ejemplo n.º 20
0
        /// <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;
            }
        }
Ejemplo n.º 21
0
        /// <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;
            }
        }
Ejemplo n.º 22
0
        /// <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;
            }
        }
Ejemplo n.º 23
0
        /// <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
            }
        }
Ejemplo n.º 24
0
        /// <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);
        }
Ejemplo n.º 25
0
        /// <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];
        }
Ejemplo n.º 26
0
 public static void UseEventLog(EventLog event_log)
 {
     if (event_log == null) throw new ArgumentNullException("event_log");
     Type = EventLogTypes.Windows;
     m_event_log = event_log;
 }