コード例 #1
0
        private void WriteRegularColumns(NpgsqlBinaryImporter writer, LogEvent logEvent)
        {
            foreach (var column in _columnOptions.Store)
            {
                switch (column)
                {
                case StandardColumn.Message:
                    var message = logEvent.RenderMessage(_formatProvider);
                    writer.WriteNullable(message, NpgsqlDbType.Text);
                    break;

                case StandardColumn.MessageTemplate:
                    var messageTemplate = logEvent.MessageTemplate.Text;
                    writer.WriteNullable(messageTemplate, NpgsqlDbType.Text);
                    break;

                case StandardColumn.Level:
                    WriteLevel(writer, logEvent);
                    break;

                case StandardColumn.TimeStamp:
                    var timestamp = _columnOptions.TimeStamp.ConvertToUtc ? logEvent.Timestamp.DateTime.ToUniversalTime() : logEvent.Timestamp.DateTime;
                    writer.Write(timestamp, NpgsqlDbType.TimestampTZ);
                    break;

                case StandardColumn.Exception:
                    var exception = logEvent.Exception?.ToString();
                    writer.WriteNullable(exception, NpgsqlDbType.Text);
                    break;

                case StandardColumn.Properties:
                    var propertiesJson = ConvertPropertiesToJsonStructure(logEvent.Properties);
                    writer.Write(propertiesJson, NpgsqlDbType.Jsonb);
                    break;

                case StandardColumn.LogEvent:
                    var logEventJson = LogEventToJson(logEvent);
                    writer.Write(logEventJson, NpgsqlDbType.Jsonb);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }