public LogMessage(string message, int eventId, EventSeverity severity, string category)
 {
     this.Message       = message;
     this.EventId       = eventId;
     this.EventSeverity = severity;
     this.Category      = category;
 }
Esempio n. 2
0
        public static void LogInfo(String category, String data)
        {
            const TraceSeverity tSeverity = TraceSeverity.Verbose;
            const EventSeverity eSeverity = EventSeverity.Verbose;

            SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(category, tSeverity, eSeverity), tSeverity, "Data:  {0}", new object[] { data });
        }
Esempio n. 3
0
        public int LoadFromDataReader(SqlDataReader dr)
        {
            int o = -1;

            this.eventId         = dr.GetInt64(++o);
            this.userGuid        = dr.GetGuid(++o);
            this.jobGuid         = dr.GetGuid(++o);
            this.contextGuid     = dr.GetGuid(++o);
            this.eventSource     = (EventSource)dr.GetInt32(++o);
            this.eventSeverity   = (EventSeverity)dr.GetInt32(++o);
            this.eventDateTime   = dr.GetDateTime(++o);
            this.eventOrder      = dr.GetInt64(++o);
            this.executionStatus = (ExecutionStatus)dr.GetInt32(++o);
            this.operation       = dr.GetString(++o);
            this.entityGuid      = dr.GetGuid(++o);
            this.entityGuidFrom  = dr.GetGuid(++o);
            this.entityGuidTo    = dr.GetGuid(++o);
            this.exceptionType   = dr.IsDBNull(++o) ? null : dr.GetString(o);
            this.message         = dr.IsDBNull(++o) ? null : dr.GetString(o);
            this.site            = dr.IsDBNull(++o) ? null : dr.GetString(o);
            this.stackTrace      = dr.IsDBNull(++o) ? null : dr.GetString(o);
            this.exception       = null;

            return(o);
        }
Esempio n. 4
0
        /// <summary>
        /// Writes information about an exception into the log.
        /// </summary>
        /// <param name="exception">The exception to write into the log.</param>
        /// <param name="eventId">The eventId that corresponds to the event. This value, coupled with the EventSource is often used by
        /// administrators and IT PRo's to monitor the EventLog of a system.</param>
        /// <param name="severity">The severity of the exception.</param>
        /// <param name="category">The category to write the message to.</param>
        public void LogToOperations(Exception exception, int eventId, EventSeverity severity,
                                    string category)
        {
            Validation.ArgumentNotNull(exception, "exception");

            WriteLogMessage(BuildExceptionMessage(exception, null), eventId, severity, category);
        }
Esempio n. 5
0
 public static void WriteAppEvent(this OperationContext context, string category, string eventType,
                                  string message, EventSeverity severity = EventSeverity.Info, string stringParam = null,
                                  int?intParam = null, Guid?guidParam = null)
 {
     context.Log.AddEntry(new AppEventEntry(context.LogContext, category, eventType, severity, message,
                                            intParam, stringParam, guidParam));
 }
Esempio n. 6
0
        public static void LogException(String category, Exception exception)
        {
            const TraceSeverity tSeverity = TraceSeverity.Unexpected;
            const EventSeverity eSeverity = EventSeverity.Error;

            SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(category, tSeverity, eSeverity), tSeverity, "Error Data:  {0}", new object[] { exception.ToString() });
        }
        private static Level GetLevelFromSeverity(EventSeverity severity)
        {
            switch (severity)
            {
            case EventSeverity.Informational:
                return(Level.Info);

            case EventSeverity.Warning:
                return(Level.Warn);

            case EventSeverity.Debug:
                return(Level.Debug);

            case EventSeverity.Error:
                return(Level.Error);

            case EventSeverity.Fatal:
                return(Level.Fatal);

            case EventSeverity.Verbose:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(severity), severity, null);
            }
            return(Level.Info);
        }
        protected virtual string CreateLogMessage(EventSeverity eventSeverity, string message, string codePoint, Dictionary <string, string> data, string callerMemberName, string callerFilePath, int callerLineNumber, DateTime now)
        {
            Dictionary <string, string> props = data.Safe();

            if (!this.EmitAdditionalData)
            {
                props = new Dictionary <string, string>();
            }

            this.AddCodepoint(message, codePoint, callerMemberName, callerFilePath, callerLineNumber, props);
            this.AddCallerFilePath(callerFilePath, props);
            this.AddCallerLineNumber(callerLineNumber, props);
            this.AddCallerMemberName(callerMemberName, props);

            if (this.EmitCorrelationContext)
            {
                props[nameof(this.CorrelationContext)] = this.CorrelationContext.Get();
            }

            this.CreateLogMessageAppendSpecificTelemetry(props);

            string json = Newtonsoft.Json.JsonConvert.SerializeObject(props);

            string log = $"[{GetTimeString(now)}][{eventSeverity.ToString()}]{message}|{json}";

            return(log);
        }
Esempio n. 9
0
        private static TraceEventType TranslateEvent(EventSeverity severity)
        {
            switch (severity)
            {
            case EventSeverity.Debug:
                return(TraceEventType.Verbose);

            case EventSeverity.Verbose:
                return(TraceEventType.Verbose);

            case EventSeverity.Info:
            case EventSeverity.Event:
            case EventSeverity.Metric:
            case EventSeverity.OperationInfo:
            case EventSeverity.Silent:
                return(TraceEventType.Information);

            case EventSeverity.Warning:
                return(TraceEventType.Warning);

            case EventSeverity.Error:
            case EventSeverity.OperationError:
                return(TraceEventType.Error);

            case EventSeverity.Fatal:
                return(TraceEventType.Critical);

            default:
                return(TraceEventType.Information);
            }
        }
Esempio n. 10
0
        private string GetSeverityAsString(EventSeverity eventSeverity)
        {
            switch (eventSeverity)
            {
            case EventSeverity.Informational:
                return("INFO");

            case EventSeverity.Warning:
                return("WARNING");

            case EventSeverity.Error:
                return("ERROR");

            case EventSeverity.Fatal:
                return("FATAL");

            case EventSeverity.Debug:
                return("DEBUG");

            case EventSeverity.Verbose:
                return("VERBOSE");

            default:
                throw new ArgumentOutOfRangeException(nameof(eventSeverity), eventSeverity, null);
            }
        }
Esempio n. 11
0
        public bool Trace(EventSeverity eventSeverity, string message, Exception exception, string codePoint = null, Dictionary <string, string> data = null, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = -1)
        {
            if (!TelemetryEnabled)
            {
                return(true);
            }

            try
            {
                string msg = CreateTraceMessage(message, exception, codePoint, data);

                int randoId;
                unchecked
                {
                    int hash = (int)2166136261;

                    hash = (hash * 16777619) ^ (int)eventSeverity;
                    hash = (hash * 16777619) ^ (int)msg.GetHashCode();

                    randoId = Math.Abs(hash) % 65535;
                }

                this.diagnosticTraceSource.TraceEvent(
                    TranslateEvent(eventSeverity),
                    randoId,
                    msg);

                return(true);
            }
            catch
            {
                // we are lost
                return(false);
            }
        }
Esempio n. 12
0
        public void Write(string message, Exception exception, EventSeverity severity)
        {
            var dateTimeFormat = string.IsNullOrWhiteSpace(DateTimeFormat) ? $"yyyy-MM-dd HH:mm:ss" : DateTimeFormat;

            Write(message, severity);
            Console.WriteLine($"[{DateTime.Now.ToString(dateTimeFormat)}][{GetSeverityAsString(severity)}] {exception}");
        }
Esempio n. 13
0
 public DiagnosticEvent(string category, Exception error)
 {
     Severity = EventSeverity.Error;
     Message = error.Message;
     ErrorInfo = error.ToString();
     Category = category;
 }
        public void LogEvent(int userId, EventType eventType, EventSeverity severity)
        {
            using (var db = new SAMEntities())
            {
                try
                {
                    var eventSeverity        = severity.ToString();
                    var eventTypeDescription = eventType.ToString();
                    var eventTypeId          = eventType.GetEnumValue();

                    var eventLog = new SAM1.EventLog
                    {
                        CreateDate      = DateTime.Now,
                        UserId          = userId,
                        EventSeverityId = (int)severity,
                        MetaData        = metaData,
                        EventTypeId     = eventTypeId,
                    };

                    db.EventLogs.Add(eventLog);
                    db.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    var errorMessages = ex.EntityValidationErrors
                                        .SelectMany(x => x.ValidationErrors)
                                        .Select(x => x.ErrorMessage + " " + x.PropertyName);

                    var fullErrorMessage = string.Join(" => ", errorMessages);
                    var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);
                    throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                }
            }
        }
Esempio n. 15
0
        public bool Trace(EventSeverity eventSeverity, string message, string codePoint = null, Dictionary <string, string> data = null, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = -1)
        {
            try
            {
                DateTime eventTime = DateTime.UtcNow;

                ConsoleEvent evt = new ConsoleEvent()
                {
                    CallerFilePath     = callerFilePath,
                    CallerLineNumber   = callerLineNumber,
                    CallerMemberName   = callerMemberName,
                    CodePoint          = codePoint,
                    Data               = data,
                    EventSeverity      = eventSeverity,
                    EventTime          = eventTime,
                    Message            = message,
                    CorrelationContext = this.CorrelationContext.ToString()
                };

                this.eventQueue.Enqueue(evt);
                this.OnEventQueued(evt);



                return(true);
            }
            catch (Exception ex)
            {
                DiagnosticTrace.Instance.Error("An unexpected exception has occured when attemtping to enqueue a log event, the event has been lost. ", ex, "DSA7WAaQrUM");
                return(false);
            }
        }
 protected DiagnosticsService(string productName, string logCategory, TraceSeverity defaultTraceLevel, EventSeverity defaultEventLevel) :
     base(string.Format(NameFormat, productName, logCategory), SPFarm.Local)
 {
     ProductName = productName;
     LogCategory = logCategory;
     DefaultTraceLevel = defaultTraceLevel;
     DefaultEventLevel = defaultEventLevel;
 }
Esempio n. 17
0
 public EventLog(String source, EventSeverity severity, Exception exception, String messageFormat, params object[] args)
 {
     LogTime = DateTime.Now;
     Source = source;
     Severity = severity;
     Message = String.Format(messageFormat, args);
     CapturedException = exception;
 }
Esempio n. 18
0
        public virtual void LogEvent(string message, int eventId, EventSeverity severity, string categoryName)
        {
            Validation.ArgumentNotNullOrEmpty(message, "message");

            SPDiagnosticsCategory category = GetCategory(categoryName);

            LogEvent(message, eventId, severity, category);
        }
 protected DiagnosticsService(string productName, string logCategory, TraceSeverity defaultTraceLevel, EventSeverity defaultEventLevel) :
     base(string.Format(NameFormat, productName, logCategory), SPFarm.Local)
 {
     ProductName       = productName;
     LogCategory       = logCategory;
     DefaultTraceLevel = defaultTraceLevel;
     DefaultEventLevel = defaultEventLevel;
 }
Esempio n. 20
0
 protected virtual void TraceDiagnostic(
     EventSeverity eventSeverity,
     string message,
     string codePoint,
     string serializedData)
 {
     Diag($"TRACE EMIT {eventSeverity.ToString()}/{message}/{codePoint ?? "ncp"}/{serializedData ?? "nsd"}");
 }
Esempio n. 21
0
 public EventLog(String source, EventSeverity severity, Exception exception, String messageFormat, params object[] args)
 {
     LogTime           = DateTime.Now;
     Source            = source;
     Severity          = severity;
     Message           = String.Format(messageFormat, args);
     CapturedException = exception;
 }
Esempio n. 22
0
        internal static void LogEvent(string subject, string body, TraceSeverity traceSeverity, EventSeverity eventSeverity, uint uid = 0)
        {
            SPDiagnosticsService diagSvc = SPDiagnosticsService.Local;

            diagSvc.WriteTrace(uid,
                new SPDiagnosticsCategory("STAFix category", traceSeverity, eventSeverity),
                traceSeverity,
                subject.ToString() + ":  {0}",
                new object[] { body.ToString() });
        }
        public void TestSetGetSeverity()
        {
            CubeSatCommSim.Model.EventSeverity expectedSeverity = CubeSatCommSim.Model.EventSeverity.WARNING;

            SimEvent newSimEvent = new SimEvent("log", CubeSatCommSim.Model.EventSeverity.INFO);
            newSimEvent.Severity = CubeSatCommSim.Model.EventSeverity.WARNING;
            EventSeverity actualSeverity = newSimEvent.Severity;

            Assert.AreEqual(expectedSeverity, actualSeverity);
        }
Esempio n. 24
0
        protected override void WriteToOperationsLog(string message, int eventId, EventSeverity severity, string category)
        {
            var messageToAdd = new LoggedMessage();

            messageToAdd.Message       = message;
            messageToAdd.EventId       = eventId;
            messageToAdd.EventSeverity = severity;
            messageToAdd.Category      = category;
            Messages.Add(messageToAdd);
        }
Esempio n. 25
0
        /// <summary>
        /// Sets the severity for the condition without raising events.
        /// </summary>
        /// <param name="context">The system context.</param>
        /// <param name="severity">The event severity.</param>
        /// <remarks>This method ensures all related variables are set correctly.</remarks>
        public virtual void SetSeverity(ISystemContext context, EventSeverity severity)
        {
            this.LastSeverity.Value = this.Severity.Value;
            this.Severity.Value     = (ushort)severity;

            if (this.LastSeverity.SourceTimestamp != null)
            {
                this.LastSeverity.SourceTimestamp.Value = DateTime.UtcNow;
            }
        }
Esempio n. 26
0
 public static void Log(string message, TraceSeverity traceSeverity, EventSeverity eventSeverity, TraceCategory category)
 {
     try
     {
         WriteTrace(category, traceSeverity, message);
         //LdapcpLoggingService.WriteEvent(LdapcpLoggingService.TraceCategory.LDAPCP, eventSeverity, message);
     }
     catch
     {   // Don't want to do anything if logging goes wrong, just ignore and continue
     }
 }
Esempio n. 27
0
 public AppEventEntry(LogContext context, string category, string eventType, EventSeverity severity, string message,
                      int?intParam = null, string stringParam = null, Guid?guidParam = null) : base(context)
 {
     Category    = category;
     EventType   = eventType;
     Severity    = severity;
     Message     = message;
     StringParam = stringParam;
     IntParam    = intParam;
     GuidParam   = guidParam;
 }
        /// <summary>
        /// Triggers an event with a given severity.
        /// </summary>
        /// <param name="summary">A high-level, text summary message of the event. Will be used to construct an alert's description.</param>
        /// <param name="component">The part or component of the affected system that is broken.</param>
        /// <param name="eventSeverity">How impacted the affected system is. Displayed to users in lists and influences the priority of any created incidents.</param>
        /// <param name="dedupKey">Deduplication key for correlating triggers and resolves. If the event must be added to an existing alert,
        /// the provided dedup key must be equal to all the other events of the alert. If it is a new alert, the dedup key must be null.</param>
        /// <returns>The event response.</returns>
        public EventResponse Trigger(string summary, string component, EventSeverity eventSeverity, Guid?dedupKey = null)
        {
            TriggerEvent triggerEvent = New()
                                        .SetSummary(summary)
                                        .SetComponent(component)
                                        .SetSeverity(eventSeverity)
                                        .SetCustomDetails(CustomDetails)
                                        .SetDedupKey(dedupKey);

            return(Pager.EnqueueEvent(triggerEvent));
        }
Esempio n. 29
0
 public static void LogToULS(string message, TraceSeverity traceSeverity, EventSeverity eventSeverity)
 {
     try
     {
         SPDiagnosticsCategory category = new SPDiagnosticsCategory("Zimbra Settings", traceSeverity, eventSeverity);
         SPDiagnosticsService  ds       = SPDiagnosticsService.Local;
         ds.WriteTrace(0, category, traceSeverity, message);
     }
     catch
     {
     }
 }
Esempio n. 30
0
 public void LogToOperations(Exception ex, LogCategories category, EventSeverity severity, string message, params object[] args)
 {
     try
     {
         logger.LogToOperations(ex, String.Format(message, args), GetEventId(category),
              severity, category.ToLoggerString());
     }
     catch
     {
         //don't want the app to fail because of failures in logging
     }
 }
 public static void LogToULS(string message, TraceSeverity traceSeverity, EventSeverity eventSeverity)
 {
     try
     {
         var category = new SPDiagnosticsCategory(CustomClaimsProvider.ProviderInternalName, traceSeverity, eventSeverity);
         var ds       = SPDiagnosticsService.Local;
         ds.WriteTrace(0, category, traceSeverity, message);
     }
     catch
     {
     }
 }
Esempio n. 32
0
 public EventLogEntry(string category, string eventType, EventSeverity severity, string message, string details = null,
                      Guid?objectId            = null, string objectName = null, int?intParam = null,
                      OperationContext context = null) : base(context, LogEntryType.Event)
 {
     Category   = category;
     EventType  = eventType;
     Severity   = severity;
     Message    = message;
     Details    = details;
     ObjectId   = objectId;
     ObjectName = objectName;
     IntParam   = intParam;
 }
Esempio n. 33
0
 protected override void WriteToOperationsLog(string message, int eventId, EventSeverity severity, string category)
 {
     try
     {
         EventLogLogger.Log(message, eventId, severity, category);
     }
     catch (Exception ex)
     {
         // If the logging failed, throw an error that holds both the original error information and the
         // reason why logging failed. Dont do this if only the tracing failed.
         throw BuildLoggingException(message, ex);
     }
 }
Esempio n. 34
0
 public DatabaseEvent(
     DatabaseEventType eventType,
     Progress progress      = null,
     string message         = null,
     EventSeverity severity = EventSeverity.Message,
     Uri uri = null)
 {
     EventType = eventType;
     Severity  = severity;
     Progress  = progress;
     Message   = message ?? (string)Convert.ChangeType(eventType, typeof(string));
     Uri       = uri;
 }
Esempio n. 35
0
        public void AddEntry(string text, EventSeverity severity)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(DateTime.Now).Append(" | ");
            builder.Append(severity.ToString()).Append(" | ");
            builder.Append(text);
            string record = builder.ToString();

            lock (_sync)
            {
                eventQueue.Enqueue(record);
            }
        }
Esempio n. 36
0
        public static void WriteEvent(EventSeverity eventSeverity, string message)
        {
            if (string.IsNullOrEmpty(message))
                return;

            var service = Local;

            if (service == null)
                return;

            try
            {
                var category = service.Areas[AreaName].Categories[Categories.Default];
                service.WriteEvent(1, category, eventSeverity, message);
            }
            catch { }
        }
Esempio n. 37
0
 private Level GetLevelFromSeverity(EventSeverity severity)
 {
     switch (severity)
     {
         case EventSeverity.Info:
             return Level.Info;
         case EventSeverity.Debug:
             return Level.Debug;
         case EventSeverity.Warning:
             return Level.Warn;
         case EventSeverity.Fatal:
             return Level.Fatal;
         case EventSeverity.Error:
             return Level.Error;
         default:
             return Level.Info;
     }
 }
Esempio n. 38
0
        /// <summary>
        /// Initializes a new event.
        /// </summary>
        /// <param name="context">The current system context.</param>
        /// <param name="source">The source of the event.</param>
        /// <param name="severity">The severity for the event.</param>
        /// <param name="message">The default message.</param>
        public virtual void Initialize(
            ISystemContext context, 
            NodeState source, 
            EventSeverity severity,
            LocalizedText message)
        {
            m_eventId = new PropertyState<byte[]>(this);
            m_eventId.Value = Guid.NewGuid().ToByteArray();

            m_eventType = new PropertyState<NodeId>(this);
            m_eventType.Value = GetDefaultTypeDefinitionId(context.NamespaceUris);

            TypeDefinitionId = m_eventType.Value;

            if (source != null)
            {
                if (!NodeId.IsNull(source.NodeId))
                {
                    m_sourceNode = new PropertyState<NodeId>(this);
                    m_sourceNode.Value = source.NodeId;
                }

                if (!QualifiedName.IsNull(source.BrowseName))
                {
                    m_sourceName = new PropertyState<string>(this);
                    m_sourceName.Value = source.BrowseName.Name;
                }
            }

            m_time = new PropertyState<DateTime>(this);
            m_time.Value = DateTime.UtcNow;

            m_receiveTime = new PropertyState<DateTime>(this);
            m_receiveTime.Value = DateTime.UtcNow;

            m_severity = new PropertyState<ushort>(this);
            m_severity.Value = (ushort)severity;

            m_message = new PropertyState<LocalizedText>(this);
            m_message.Value = message;
        }
Esempio n. 39
0
        /// <summary>
        /// Initializes a new event.
        /// </summary>
        /// <param name="context">The current system context.</param>
        /// <param name="source">The source of the event.</param>
        /// <param name="severity">The severity for the event.</param>
        /// <param name="message">The default message.</param>
        /// <param name="status">Whether the operation that caused the event succeeded.</param>
        /// <param name="actionTimestamp">When the operation started.</param>
        public virtual void Initialize(
            ISystemContext context, 
            NodeState source, 
            EventSeverity severity,
            LocalizedText message,
            bool status,
            DateTime actionTimestamp)
        {
            base.Initialize(context, source, severity, message);

            m_status = new PropertyState<bool>(this);
            m_status.Value = status;

            if (actionTimestamp != DateTime.MinValue)
            {
                m_actionTimeStamp = new PropertyState<DateTime>(this);
                m_actionTimeStamp.Value = actionTimestamp;
            }

            if (context.NamespaceUris != null)
            {
                m_serverId = new PropertyState<string>(this);
                m_serverId.Value = context.NamespaceUris.GetString(1);
            }

            if (context.AuditEntryId != null)
            {
                m_clientAuditEntryId = new PropertyState<string>(this);
                m_clientAuditEntryId.Value = context.AuditEntryId;
            }

            if (context.UserIdentity != null)
            {
                m_clientUserId = new PropertyState<string>(this);
                m_clientUserId.Value = context.UserIdentity.DisplayName;
            }
        }
Esempio n. 40
0
        private void CopyMembers(Event old)
        {
            this.eventId = old.eventId;
            this.userGuid = old.userGuid;
            this.jobGuid = old.jobGuid;
            this.contextGuid = old.contextGuid;
            this.eventSource = old.eventSource;
            this.eventSeverity = old.eventSeverity;
            this.eventDateTime = old.eventDateTime;
            this.eventOrder = old.eventOrder;
            this.executionStatus = old.executionStatus;
            this.operation = old.operation;
            this.entityGuid = old.entityGuid;
            this.entityGuidFrom = old.entityGuidFrom;
            this.entityGuidTo = old.entityGuidTo;
            this.exceptionType = old.exceptionType;
            this.site = old.site;
            this.message = old.message;
            this.stackTrace = old.stackTrace;

            this.userData = new Dictionary<string, object>(old.userData);
            this.exception = old.exception;
        }
Esempio n. 41
0
        /// <summary>
        /// Actually controls the writing. Calls to WriteEvent ALSO writes to the ULS log. That's why the public logging methods
        /// all use TraceSeverity.None.
        /// </summary>
        private void WriteLog(SPDiagnosticsCategory category, TraceSeverity trcSeverity, EventSeverity evtSeverity, string message)
        {
            //uint catId = (uint)category;
            //SPDiagnosticsCategory diagCat = MyLogger.Local.Areas[DiagnosticsAreaName].Categories[catId];

            StackTrace stackTrace = new StackTrace();
            StackFrame stackFrame = stackTrace.GetFrame(2);
            MethodBase methodBase = stackFrame.GetMethod();

            message = string.Format("{0}.{1} : {2}",
                                        methodBase.DeclaringType.Name,
                                        methodBase.Name,
                                        message);

            if (evtSeverity != EventSeverity.None)
            {
                //Problem - event source might not be registered on Server, and the app pool might not be able to create it.
                //Therefore, catch the exception, and write it into the logs. Nothing gets written to the Windows log,
                //but at least it's somewhat handled.
                try
                {
                    base.WriteEvent(0, category, evtSeverity, message);
                }
                catch (Exception ex)
                {
                    base.WriteTrace(0, category, TraceSeverity.Unexpected, string.Format("Unable to write to event log {0} : {1}", ex.GetType().ToString(), ex.Message));

                    // If there was an error writing to the event log, make sure the tracelog is written to instead.
                    switch (evtSeverity)
                    {
                        case EventSeverity.Error:
                            trcSeverity = TraceSeverity.Unexpected;
                            break;
                        case EventSeverity.Warning:
                            trcSeverity = TraceSeverity.Monitorable;
                            break;
                        case EventSeverity.Information:
                            trcSeverity = TraceSeverity.High;
                            break;
                    }
                }
            }

            if (trcSeverity != TraceSeverity.None)
            {
                base.WriteTrace(0, category, trcSeverity, message);
            }
        }
Esempio n. 42
0
 private SPDiagnosticsCategory newSPDiagnosticsCategory(string p, TraceSeverity traceSeverity, EventSeverity eventSeverity)
 {
     throw new NotImplementedException();
 }
Esempio n. 43
0
 /// <summary>
 /// Override this method to implement how to write to a log message.
 /// </summary>
 /// <param name="message">The message to write into the log.</param>
 /// <param name="eventId">
 /// The eventId that corresponds to the event. This value, coupled with the EventSource is often used by
 /// administrators and IT PRo's to monitor the EventLog of a system. 
 /// </param>
 /// <param name="severity">How serious the event is. </param>
 /// <param name="category">The category of the log message.</param>
 protected abstract void WriteToOperationsLog(string message, int eventId, EventSeverity severity, string category);
Esempio n. 44
0
        /// <summary>
        /// Logs an event
        /// </summary>
        /// <param name="es">
        /// The event severity
        /// </param>
        /// <param name="eventDesc">
        /// The event description
        /// </param>
        public void LogEvent(EventSeverity es, string eventDesc)
        {
            // Create the log line
            string logLine =
                    String.Format(
                        "{0}    {1}: {2}\n",
                        DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss tt"),
                        es.ToString(),
                        eventDesc);

            // Logging to a file
            if ((_logEndpoint & LogLocation.File) == LogLocation.File)
            {
                // Do we need to open a new log file?
                if (_fileHour != DateTime.Now.Hour)
                    OpenLogFile();

                // Log the event
                _fileWriter.Write(logLine);

                // Write the event to disk
                _fileWriter.Flush();
            }

            // Logging to the console
            if ((_logEndpoint & LogLocation.Console) == LogLocation.Console)
                Console.Write(logLine);
        }
        /// <summary>
        /// Sets the severity for the condition without raising events.
        /// </summary>
        /// <param name="context">The system context.</param>
        /// <param name="severity">The event severity.</param>
        /// <remarks>This method ensures all related variables are set correctly.</remarks>
        public virtual void SetSeverity(ISystemContext context, EventSeverity severity)
        {
            this.LastSeverity.Value = this.Severity.Value;
            this.Severity.Value = (ushort)severity;

            if (this.LastSeverity.SourceTimestamp != null)
            {
                this.LastSeverity.SourceTimestamp.Value = DateTime.UtcNow;
            }
        }
Esempio n. 46
0
 public void LogToOperations(string message, int eventId, EventSeverity severity) {
     throw new NotImplementedException();
 }
Esempio n. 47
0
        /// <summary>
        /// Writes the logged message to the operations log 
        /// </summary>
        /// <param name="message">The message to write into the log.</param>
        /// <param name="eventId">
        /// The eventId that corresponds to the event. This value, coupled with the EventSource is often used by
        /// administrators and IT PRo's to monitor the EventLog of a system. 
        /// </param>
        /// <param name="severity">How serious the event is. </param>
        /// <param name="category">The category of the log message.</param>
        public void LogToOperations(string message, int eventId, EventSeverity severity, string category)
        {
            Validation.ArgumentNotNull(message, "message");

            WriteLogMessage(message, eventId, severity, category);
        }
Esempio n. 48
0
        /// <summary>
        /// Writes an error message into the log
        /// </summary>
        /// <param name="message">The message to write</param>
        /// <param name="severity">How serious the event is.</param>
        public void LogToOperations(string message, EventSeverity severity)
        {
            Validation.ArgumentNotNull(message, "message");

            WriteLogMessage(message, DefaultEventId, severity, null);
        }
Esempio n. 49
0
        private void InitializeMembers()
        {
            this.eventId = 0;
            this.userGuid = Guid.Empty;
            this.jobGuid = Guid.Empty;
            this.contextGuid = Guid.Empty;
            this.eventSource = EventSource.None;
            this.eventSeverity = EventSeverity.Status;
            this.eventDateTime = DateTime.Now;
            this.eventOrder = 0;
            this.executionStatus = ExecutionStatus.Executing;
            this.operation = string.Empty;
            this.entityGuid = Guid.Empty;
            this.entityGuidFrom = Guid.Empty;
            this.entityGuidTo = Guid.Empty;
            this.exceptionType = null;
            this.site = null;
            this.message = null;
            this.stackTrace = null;

            this.userData = new Dictionary<string, object>();
            this.exception = null;
        }
Esempio n. 50
0
 public void Write(string message, Exception exception, EventSeverity severity)
 {
     var level = GetLevelFromSeverity(severity);
     _internalLogger.Logger.Log(MethodBase.GetCurrentMethod().DeclaringType, level, message, exception);
 }
Esempio n. 51
0
 public void Write(string message, EventSeverity severity)
 {
     Write(message, null, severity);
 }
Esempio n. 52
0
 private void InitializeMembers()
 {
     this.eventDateTimeFrom = DateTime.MinValue;
     this.eventDateTimeTo = DateTime.MaxValue;
     this.eventSource = EventSource.All;
     this.eventSeverity = EventSeverity.All;
     this.executionStatus = new List<ExecutionStatus>();
     this.userGuid = Guid.Empty;
     this.jobGuid = Guid.Empty;
     this.contextGuid = Guid.Empty;
     this.operation = string.Empty;
     this.entityGuid = Guid.Empty;
     this.exceptionType = string.Empty;
     this.message = string.Empty;
 }
Esempio n. 53
0
        public int LoadFromDataReader(SqlDataReader dr)
        {
            int o = -1;

            this.eventId = dr.GetInt64(++o);
            this.userGuid = dr.GetGuid(++o);
            this.jobGuid = dr.GetGuid(++o);
            this.contextGuid = dr.GetGuid(++o);
            this.eventSource = (EventSource)dr.GetInt32(++o);
            this.eventSeverity = (EventSeverity)dr.GetInt32(++o);
            this.eventDateTime = dr.GetDateTime(++o);
            this.eventOrder = dr.GetInt64(++o);
            this.executionStatus = (ExecutionStatus)dr.GetInt32(++o);
            this.operation = dr.GetString(++o);
            this.entityGuid = dr.GetGuid(++o);
            this.entityGuidFrom = dr.GetGuid(++o);
            this.entityGuidTo = dr.GetGuid(++o);
            this.exceptionType = dr.IsDBNull(++o) ? null : dr.GetString(o);
            this.message = dr.IsDBNull(++o) ? null : dr.GetString(o);
            this.site = dr.IsDBNull(++o) ? null : dr.GetString(o);
            this.stackTrace = dr.IsDBNull(++o) ? null : dr.GetString(o);
            this.exception = null;

            return o;
        }
Esempio n. 54
0
        /// <summary>
        /// Writes information about an exception into the log.
        /// </summary>
        /// <param name="exception">The exception to write into the log to be read by operations.</param>
        /// <param name="additionalMessage">Additional information about the exception message.</param>
        /// <param name="eventId">The eventId that corresponds to the event. This value, coupled with the EventSource is often used by
        /// administrators and IT PRo's to monitor the EventLog of a system.</param>
        /// <param name="severity">The severity of the exception.</param>
        /// <param name="category">The category to write the message to.</param>
        public void LogToOperations(Exception exception, string additionalMessage, int eventId,
                                             EventSeverity severity, string category)
        {
            Validation.ArgumentNotNull(exception, "exception");
            Validation.ArgumentNotNull(additionalMessage, "additionalMessage"); 

            WriteLogMessage(BuildExceptionMessage(exception, additionalMessage), eventId, severity, category);
        }
Esempio n. 55
0
 public void LogToOperations(Exception exception, string additionalMessage, int eventId, EventSeverity severity, string category) {
     throw new NotImplementedException();
 }
Esempio n. 56
0
 /// <summary>
 /// Safe method to trace to the sandbox.
 /// </summary>
 /// <param name="message">The message to trace</param>
 /// <param name="eventId">the event id to trace</param>
 /// <param name="severity">the sandbox severity to use</param>
 /// <param name="category">The category to trace under</param>
 private void WriteLogMessage(string message, int eventId, EventSeverity severity, string category)
 {
     string logMsg = BuildEventLogMessage(message, eventId, severity, category);
     WriteToOperationsLog(logMsg, eventId, severity, category);
 }
Esempio n. 57
0
 public Event( string message, EventSeverity eventSeverity )
 {
     _message = message ;
     _eventSeverity = eventSeverity ;
 }
Esempio n. 58
0
 /// <summary>
 /// Override this method to change the way the log message is created. 
 /// </summary>
 /// <param name="message">The message to write into the log.</param>
 /// <param name="eventId">
 /// The event Id that corresponds to the event. This value, coupled with the EventSource is often used by
 /// administrators and IT PRo's to monitor the EventLog of a system. 
 /// </param>
 /// <param name="severity">How serious the event is. </param>
 /// <param name="category">The category of the log message.</param>
 /// <returns>The message.</returns>
  protected virtual string BuildEventLogMessage(string message, int eventId, EventSeverity severity,
                                            string category)
 {
     return message;
 }
Esempio n. 59
0
 /// <summary>
 /// Logs an exception
 /// </summary>
 /// <param name="ex">
 /// The exception to log
 /// </param>
 /// <param name="es">
 /// The severity to log
 /// </param>
 public void LogException(Exception ex, EventSeverity es)
 {
     LogEvent(es, ex.Message);
     LogEvent(es, "Stack Trace:" + ex.StackTrace);
 }
Esempio n. 60
0
 /// <summary>
 /// Logs a socket exception
 /// </summary>
 /// <param name="ex">
 /// The SocketException to log
 /// </param>
 /// <param name="es">
 /// The severity to log
 /// </param>
 public void LogSocketException(SocketException ex, EventSeverity es)
 {
     LogEvent(es, ex.Message);
     LogEvent(es, "Socket Error Code: " + ex.SocketErrorCode);
     LogEvent(es, "Stack Trace:" + ex.StackTrace);
 }