Я использую пакет Serilog.Sinks.MSSqlServer версии 5.8.0
Я использую эту конфигурацию для создания собственных столбцов
Код: Выделить всё
`var dbColumnOptions = new ColumnOptions
{
AdditionalDataColumns = new Collection
{
new DataColumn {DataType = typeof(string), ColumnName = "Controller"},
new DataColumn {DataType = typeof(string), ColumnName = "Route"},
new DataColumn {DataType = typeof(string), ColumnName = "StatusCode"},
new DataColumn {DataType = typeof(string), ColumnName = "Method"},
new DataColumn {DataType = typeof(string), ColumnName = "Request"},
new DataColumn {DataType = typeof(string), ColumnName = "Response"}
}
};
dbColumnOptions.Store.Remove(StandardColumn.Properties);
dbColumnOptions.Store.Remove(StandardColumn.MessageTemplate);
dbColumnOptions.Store.Remove(StandardColumn.LogEvent);
dbColumnOptions.TimeStamp.ConvertToUtc = true;
LoggerConfiguration loggerConfig = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.MSSqlServer(dbLogConnection, tableName, columnOptions: dbColumnOptions, schemaName: "any", autoCreateSqlTable: true);`
Код: Выделить всё
var requestUri = string.Empty;
var httpVerb = string.Empty;
var httpStatusCode = string.Empty;
var requestBody = string.Empty;
string responseBody = string.Empty;`
requestUri = request.RequestUri.ToString();
httpVerb = request.Method.Method;
if (request.Content != null)
{
requestBody = await request.Content.ReadAsStringAsync();
}
HttpResponseMessage response = await base.SendAsync(request, cancellationToken);
httpStatusCode = ((int)response.StatusCode).ToString();
if (response.Content != null)
{
responseBody = await response.Content.ReadAsStringAsync();
}
_logger.ForContext("Controller", "Whatever")
.ForContext("Request", requestBody)
.ForContext("RouteName", requestUri)
.ForContext("HttpStatusCode", httpStatusCode)
.ForContext("HttpVerb", httpVerb)
.ForContext("Response", responseBody)
.Information("Information");
truncated response
I don't know why is happening, if I print in the console the information about the response or request the information is not truncated, only when it wrote on the DB
The entire value of the response and request bodys
Источник: https://stackoverflow.com/questions/781 ... n-database
Мобильная версия