示例#1
0
        public static string FormatCollection(IEnumerable data, bool escapeLineBreaks, out bool needsEscaping)
        {
            StringBuilder stringBuilder = new StringBuilder(256);

            needsEscaping = false;
            foreach (object data2 in data)
            {
                bool   flag;
                string text = LogRowFormatter.Format(data2, out flag);
                if (flag)
                {
                    needsEscaping = true;
                    Utf8Csv.EscapeAndAppendCollectionMember(stringBuilder, text, escapeLineBreaks);
                }
                else
                {
                    Utf8Csv.AppendCollectionMember(stringBuilder, text);
                }
            }
            if (stringBuilder.Length > 0)
            {
                stringBuilder.Remove(stringBuilder.Length - 1, 1);
            }
            return(stringBuilder.ToString());
        }
示例#2
0
        protected virtual byte[] EncodeCollection(IEnumerable data)
        {
            bool   flag;
            string s = LogRowFormatter.FormatCollection(data, this.escapeLineBreaks, out flag);

            if (!flag)
            {
                return(Utf8Csv.Encode(s));
            }
            return(Utf8Csv.EncodeAndEscape(s, this.escapeLineBreaks));
        }
示例#3
0
 public LogRowFormatter(LogRowFormatter copy)
 {
     this.fields           = new object[copy.fields.Length];
     this.encodedFields    = new byte[copy.fields.Length][];
     this.escapeLineBreaks = copy.escapeLineBreaks;
     this.escapeRawData    = copy.escapeRawData;
     for (int i = 0; i < this.fields.Length; i++)
     {
         this.fields[i]        = copy.fields[i];
         this.encodedFields[i] = copy.encodedFields[i];
     }
 }
示例#4
0
        private LogRowFormatter CreateRow(string eventId, IEnumerable <KeyValuePair <string, object> > eventData)
        {
            if (string.IsNullOrEmpty(eventId))
            {
                throw new ArgumentException("eventId cannot be null or empty");
            }
            LogRowFormatter logRowFormatter = new LogRowFormatter(this.logSchema, this.escapeLineBreaks);

            logRowFormatter[1] = ExtensibleLogger.MachineName;
            logRowFormatter[2] = eventId;
            logRowFormatter[3] = eventData;
            return(logRowFormatter);
        }
示例#5
0
        private static void AddToLog(Guid activityId, string component, SystemProbe.Status status, string formatString, params object[] args)
        {
            string value = string.Empty;

            try
            {
                value = string.Format(CultureInfo.InvariantCulture, formatString, args);
            }
            catch (ArgumentNullException)
            {
                SystemProbe.EventLogger.LogEvent(FfoSystemProbeEventLogConstants.Tuple_SystemProbeFormatArgumentNullException, component, new object[0]);
                return;
            }
            catch (FormatException ex)
            {
                SystemProbe.EventLogger.LogEvent(FfoSystemProbeEventLogConstants.Tuple_SystemProbeFormatException, component, new object[]
                {
                    ex.Message
                });
                return;
            }
            List <KeyValuePair <string, string> > list = new List <KeyValuePair <string, string> >();

            list.Add(new KeyValuePair <string, string>("SysProbe", string.Empty));
            list.Add(new KeyValuePair <string, string>("Server", SystemProbe.hostName));
            list.Add(new KeyValuePair <string, string>("Component", component));
            list.Add(new KeyValuePair <string, string>("Status", status.ToString()));
            list.Add(new KeyValuePair <string, string>("Message", value));
            List <List <KeyValuePair <string, string> > > list2 = new List <List <KeyValuePair <string, string> > >();

            list2.Add(list);
            LogRowFormatter logRowFormatter = new LogRowFormatter(SystemProbe.sysProbeSchema);

            logRowFormatter[0]  = (SystemProbe.startTime + SystemProbe.stopwatch.Elapsed).ToString("yyyy-MM-ddTHH\\:mm\\:ss.ffffffZ", DateTimeFormatInfo.InvariantInfo);
            logRowFormatter[10] = activityId;
            logRowFormatter[11] = activityId;
            logRowFormatter[8]  = MessageTrackingEvent.SYSPROBEINFO;
            logRowFormatter[7]  = MessageTrackingSource.AGENT;
            logRowFormatter[23] = SystemProbeConstants.TenantID;
            logRowFormatter[26] = LoggingFormatter.GetAgentInfoString(list2);
            logRowFormatter[12] = new string[]
            {
                "*****@*****.**"
            };
            if (SystemProbe.log != null)
            {
                SystemProbe.log.Append(logRowFormatter, -1);
            }
        }
示例#6
0
        public void LogObject(T objectToLog)
        {
            if (!this.configuration.IsEnabled)
            {
                return;
            }
            LogRowFormatter logRowFormatter = new LogRowFormatter(this.logSchema);
            int             num             = 1;

            foreach (IObjectLogPropertyDefinition <T> objectLogPropertyDefinition in this.schemaEntries)
            {
                logRowFormatter[num++] = objectLogPropertyDefinition.GetValue(objectToLog);
            }
            this.log.Append(logRowFormatter, 0);
        }
示例#7
0
        private static string Format(object data, out bool needsEscaping)
        {
            if (data == null)
            {
                needsEscaping = false;
                return(string.Empty);
            }
            needsEscaping = true;
            string result;

            if (data is Guid)
            {
                needsEscaping = false;
                result        = ((Guid)data).ToString();
            }
            else if (data is DateTime)
            {
                needsEscaping = false;
                result        = ((DateTime)data).ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffZ", DateTimeFormatInfo.InvariantInfo);
            }
            else if (data is int)
            {
                result = ((int)data).ToString(NumberFormatInfo.InvariantInfo);
            }
            else if (data is KeyValuePair <string, object> )
            {
                result = LogRowFormatter.EncodeKeyValuePair((KeyValuePair <string, object>)data);
            }
            else if (data is float)
            {
                result = ((float)data).ToString(NumberFormatInfo.InvariantInfo);
            }
            else if (data is double)
            {
                result = ((double)data).ToString(NumberFormatInfo.InvariantInfo);
            }
            else
            {
                result = data.ToString();
            }
            return(result);
        }
        public virtual string Set(Enum property, object value)
        {
            string text = null;

            try
            {
                if (this.VerifyIsDisposed())
                {
                    return(null);
                }
                if (value != null)
                {
                    text = LogRowFormatter.Format(value);
                }
                this.ActivityScope.SetProperty(property, text);
            }
            catch (ActivityContextException exception)
            {
                ExWatson.HandleException(new UnhandledExceptionEventArgs(exception, false), ReportOptions.None);
            }
            return(text);
        }
示例#9
0
        protected virtual byte[] Encode(object data)
        {
            if (data == null)
            {
                return(null);
            }
            if (data is byte[])
            {
                return(this.EncodeBytes((byte[])data));
            }
            if (!(data is string) && data is IEnumerable)
            {
                return(this.EncodeCollection((IEnumerable)data));
            }
            bool   flag;
            string s = LogRowFormatter.Format(data, out flag);

            if (!flag)
            {
                return(Utf8Csv.Encode(s));
            }
            return(Utf8Csv.EncodeAndEscape(s, this.escapeLineBreaks));
        }
示例#10
0
        public static string Format(object data)
        {
            bool flag;

            return(LogRowFormatter.Format(data, out flag));
        }
示例#11
0
 public static string FormatCollection(IEnumerable data, out bool needsEscaping)
 {
     return(LogRowFormatter.FormatCollection(data, LogRowFormatter.DefaultEscapeLineBreaks, out needsEscaping));
 }
示例#12
0
        public static string FormatCollection(IEnumerable data)
        {
            bool flag;

            return(LogRowFormatter.FormatCollection(data, out flag));
        }
        protected override void InternalDispose(bool disposing)
        {
            if (!this.isDisposeAlreadyCalled && disposing && this.ActivityScope != null)
            {
                lock (this.SyncRoot)
                {
                    if (!this.isDisposeAlreadyCalled)
                    {
                        this.excludeLogEntry |= this.SkipLogging;
                        try
                        {
                            if (this.ActivityScope.ActivityType == ActivityType.Request)
                            {
                                this.FetchLatencyData();
                                if (!this.excludeLogEntry)
                                {
                                    this.PreCommitTasks();
                                }
                            }
                            if (this.EndActivityContext && this.ActivityScope.Status == ActivityContextStatus.ActivityStarted)
                            {
                                this.ActivityScope.End();
                            }
                            if (!this.excludeLogEntry)
                            {
                                List <KeyValuePair <string, object> > formattableMetadata = this.ActivityScope.GetFormattableMetadata();
                                formattableMetadata.RemoveAll(delegate(KeyValuePair <string, object> pair)
                                {
                                    Enum @enum = ActivityContext.LookupEnum(pair.Key);
                                    return(object.Equals(@enum, RequestDetailsLoggerBase <T> .RequestLoggerConfig.GenericInfoColumn) || object.Equals(@enum, ActivityStandardMetadata.ReturnClientRequestId) || RequestDetailsLoggerBase <T> .enumToIndexMap.ContainsKey(@enum));
                                });
                                List <KeyValuePair <string, object> > collection = WorkloadManagementLogger.FormatWlmActivity(this.ActivityScope, false);
                                formattableMetadata.AddRange(collection);
                                foreach (KeyValuePair <Enum, int> keyValuePair in RequestDetailsLoggerBase <T> .enumToIndexMap)
                                {
                                    string text = this.Get(keyValuePair.Key);
                                    if (object.Equals(RequestDetailsLoggerBase <T> .RequestLoggerConfig.GenericInfoColumn, keyValuePair.Key))
                                    {
                                        text += LogRowFormatter.FormatCollection(formattableMetadata);
                                    }
                                    if (!string.IsNullOrEmpty(text))
                                    {
                                        text = RequestDetailsLoggerBase <T> .FormatForCsv(text);

                                        this.Row[keyValuePair.Value] = text;
                                    }
                                }
                                RequestDetailsLoggerBase <T> .Log.Append(this.Row, -1);

                                this.UploadDataToStreamInsight();
                            }
                        }
                        finally
                        {
                            if (this.ActivityScope != null && this.EndActivityContext && this.ActivityScope.Status == ActivityContextStatus.ActivityStarted)
                            {
                                this.ActivityScope.End();
                            }
                            this.isDisposeAlreadyCalled = true;
                        }
                    }
                }
            }
        }
示例#14
0
        public void Append(LogRowFormatter row, int timestampField, DateTime timeStamp)
        {
            Exception ex   = null;
            string    text = null;

            lock (this.logLock)
            {
                if (this.failedToCreateDirectory)
                {
                    ExTraceGlobals.CommonTracer.TraceError <string>(26473, (long)this.GetHashCode(), "Cannot append to the {0} logs because we failed to create the logging directory", this.logComponent);
                    if (!this.handleKnownExceptions)
                    {
                        throw new InvalidOperationException("Not configured");
                    }
                    return;
                }
                else
                {
                    if (this.handleKnownExceptions && this.donotAppend && ++this.donotAppendCount < this.maxWaitAppendCount)
                    {
                        ExTraceGlobals.CommonTracer.TraceError <string, int>(22377, (long)this.GetHashCode(), "Not appending to the {0} logs. Failed to log in previous attempts. Will wait {1} times before retrying", this.logComponent, this.maxWaitAppendCount - this.donotAppendCount);
                        return;
                    }
                    if (this.logDirectory == null)
                    {
                        throw new InvalidOperationException("Cannot append to a closed log.");
                    }
                    this.donotAppend = false;
                    DateTime utcNow = DateTime.UtcNow;
                    if (timestampField >= 0)
                    {
                        row[timestampField] = ((timeStamp != DateTime.MinValue) ? timeStamp : utcNow);
                    }
                    try
                    {
                        Stream logFile = this.logDirectory.GetLogFile(utcNow, this.headerFormatter, this.TestHelper_ForceLogFileRollOver);
                        if (logFile == null)
                        {
                            this.donotAppend      = true;
                            this.donotAppendCount = 1;
                            text = "Couldn't create a new log file";
                        }
                        else
                        {
                            row.Write(logFile);
                            LogDirectory.BufferedStream bufferedStream = logFile as LogDirectory.BufferedStream;
                            if (bufferedStream != null && bufferedStream.BufferSize == 0)
                            {
                                bufferedStream.Flush();
                            }
                        }
                    }
                    catch (IOException ex2)
                    {
                        ex = ex2;
                        this.donotAppend      = true;
                        this.donotAppendCount = 1;
                        text = ex2.Message;
                    }
                    catch (UnauthorizedAccessException ex3)
                    {
                        ex = ex3;
                        this.donotAppend      = true;
                        this.donotAppendCount = 1;
                        text = ex3.Message;
                    }
                }
            }
            if (this.donotAppend)
            {
                Log.EventLog.LogEvent(CommonEventLogConstants.Tuple_FailedToAppendLog, this.logDirectory.FullName, new object[]
                {
                    this.logComponent,
                    text
                });
            }
            if (!this.handleKnownExceptions && ex != null)
            {
                throw new LogException("log append failed", ex);
            }
        }
示例#15
0
 public void Append(LogRowFormatter row, int timestampField)
 {
     this.Append(row, timestampField, DateTime.MinValue);
 }
示例#16
0
        private void LogRow(string eventId, IEnumerable <KeyValuePair <string, object> > eventData)
        {
            LogRowFormatter row = this.CreateRow(eventId, eventData);

            this.log.Append(row, 0);
        }