Example #1
0
        private ITableEntity CreateTableEntity(LogEventInfo logEvent, string partitionKey)
        {
            if (ContextProperties.Count > 0)
            {
                DynamicTableEntity entity = new DynamicTableEntity();
                entity.PartitionKey = partitionKey;
                entity.RowKey       = string.Concat((DateTime.MaxValue.Ticks - logEvent.TimeStamp.Ticks).ToString("d19"), "__", Guid.NewGuid().ToString());
                entity.Properties.Add("LogTimeStamp", new EntityProperty(logEvent.TimeStamp.ToUniversalTime()));
                for (int i = 0; i < ContextProperties.Count; ++i)
                {
                    var contextproperty = ContextProperties[i];
                    if (string.IsNullOrEmpty(contextproperty.Name))
                    {
                        continue;
                    }

                    var propertyValue = contextproperty.Layout != null?RenderLogEvent(contextproperty.Layout, logEvent) : string.Empty;

                    entity.Properties.Add(contextproperty.Name, new EntityProperty(propertyValue));
                }
                return(entity);
            }
            else
            {
                var layoutMessage = RenderLogEvent(Layout, logEvent);
                var entity        = new NLogEntity(logEvent, layoutMessage, _machineName, partitionKey, LogTimeStampFormat);
                return(entity);
            }
        }
Example #2
0
        private ITableEntity CreateTableEntity(LogEventInfo logEvent, string partitionKey)
        {
            var rowKey = RenderLogEvent(RowKey, logEvent);

            if (ContextProperties.Count > 0)
            {
                DynamicTableEntity entity = new DynamicTableEntity();
                entity.PartitionKey = partitionKey;
                entity.RowKey       = rowKey;

                bool logTimeStampOverridden = "LogTimeStamp".Equals(ContextProperties[0].Name, StringComparison.OrdinalIgnoreCase);
                if (!logTimeStampOverridden)
                {
                    entity.Properties.Add("LogTimeStamp", new EntityProperty(logEvent.TimeStamp.ToUniversalTime()));
                }

                for (int i = 0; i < ContextProperties.Count; ++i)
                {
                    var contextproperty = ContextProperties[i];
                    if (string.IsNullOrEmpty(contextproperty.Name))
                    {
                        continue;
                    }

                    var propertyValue = contextproperty.Layout != null?RenderLogEvent(contextproperty.Layout, logEvent) : string.Empty;

                    if (logTimeStampOverridden && i == 0 && string.IsNullOrEmpty(propertyValue))
                    {
                        continue;
                    }

                    entity.Properties.Add(contextproperty.Name, new EntityProperty(propertyValue));
                }

                return(entity);
            }
            else
            {
                var layoutMessage = RenderLogEvent(Layout, logEvent);
                var entity        = new NLogEntity(logEvent, layoutMessage, _machineName, partitionKey, rowKey, LogTimeStampFormat);
                return(entity);
            }
        }