Skip to content

Commit 88ea8c2

Browse files
committed
Fix merge conflict.
2 parents 436f568 + 6c6b222 commit 88ea8c2

File tree

3 files changed

+46
-36
lines changed

3 files changed

+46
-36
lines changed

src/Serilog.Ui.MongoDbProvider/Extensions/SerilogUiOptionBuilderExtensions.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
namespace Serilog.Ui.MongoDbProvider
88
{
99
/// <summary>
10-
/// SerilogUI option builder extensions.
10+
/// MongoDB data provider specific extension methods for <see cref="SerilogUiOptionsBuilder"/>.
1111
/// </summary>
1212
public static class SerilogUiOptionBuilderExtensions
1313
{
1414
/// <summary>
15-
/// Adds MongoDB log data provider.
15+
/// Configures the SerilogUi to connect to a MongoDB database.
1616
/// </summary>
1717
/// <param name="optionsBuilder">The options builder.</param>
1818
/// <param name="connectionString">The connection string.</param>
19-
/// <param name="collectionName">Name of the collection.</param>
20-
/// <exception cref="ArgumentNullException">connectionString</exception>
21-
/// <exception cref="ArgumentNullException">collectionName</exception>
19+
/// <param name="collectionName">Name of the collection name.</param>
20+
/// <exception cref="ArgumentNullException">throw if connectionString is null</exception>
21+
/// <exception cref="ArgumentNullException">throw is collectionName is null</exception>
2222
public static void UseMongoDb(
2323
this SerilogUiOptionsBuilder optionsBuilder,
2424
string connectionString,
@@ -44,15 +44,15 @@ string collectionName
4444
}
4545

4646
/// <summary>
47-
/// Adds MongoDB log data provider.
47+
/// Configures the SerilogUi to connect to a MongoDB database.
4848
/// </summary>
4949
/// <param name="optionsBuilder">The options builder.</param>
50-
/// <param name="connectionString">The connection string without database name.</param>
51-
/// <param name="databaseName">Name of the database.</param>
52-
/// <param name="collectionName">Name of the collection.</param>
53-
/// <exception cref="ArgumentNullException">connectionString</exception>
54-
/// <exception cref="ArgumentNullException">databaseName</exception>
55-
/// <exception cref="ArgumentNullException">collectionName</exception>
50+
/// <param name="connectionString">The connection string.</param>
51+
/// <param name="databaseName">Name of the data table.</param>
52+
/// <param name="collectionName">Name of the collection name.</param>
53+
/// <exception cref="ArgumentNullException">throw if connectionString is null</exception>
54+
/// <exception cref="ArgumentNullException">throw is databaseName is null</exception>
55+
/// <exception cref="ArgumentNullException">throw is collectionName is null</exception>
5656
public static void UseMongoDb(
5757
this SerilogUiOptionsBuilder optionsBuilder,
5858
string connectionString,

src/Serilog.Ui.MongoDbProvider/MongoDbDataProvider.cs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,29 @@ private async Task<IEnumerable<LogModel>> GetLogsAsync(
4444
DateTime? startDate,
4545
DateTime? endDate)
4646
{
47-
var builder = Builders<MongoDbLogModel>.Filter.Empty;
48-
GenerateWhereClause(ref builder, level, searchCriteria, startDate, endDate);
49-
50-
var logs = await _collection
51-
.Find(builder)
52-
.Skip(count * page)
53-
.Limit(count)
54-
.SortByDescending(entry => entry.Timestamp)
55-
.ToListAsync();
56-
57-
var index = 1;
58-
foreach (var log in logs)
59-
log.Id = (page * count) + index++;
60-
61-
return logs.Select(log => log.ToLogModel()).ToList();
47+
try
48+
{
49+
var builder = Builders<MongoDbLogModel>.Filter.Empty;
50+
GenerateWhereClause(ref builder, level, searchCriteria, startDate, endDate);
51+
52+
var logs = await _collection
53+
.Find(builder)
54+
.Skip(count * page)
55+
.Limit(count)
56+
.SortByDescending(entry => entry.Timestamp)
57+
.ToListAsync();
58+
59+
var index = 1;
60+
foreach (var log in logs)
61+
log.Id = (page * count) + index++;
62+
63+
return logs.Select(log => log.ToLogModel()).ToList();
64+
}
65+
catch (Exception ex)
66+
{
67+
Console.WriteLine(ex);
68+
throw;
69+
}
6270
}
6371

6472
private async Task<int> CountLogsAsync(string level, string searchCriteria, DateTime? startDate, DateTime? endDate)

src/Serilog.Ui.MongoDbProvider/MongoDbLogModel.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using MongoDB.Bson.Serialization.Attributes;
1+
using MongoDB.Bson;
2+
using MongoDB.Bson.Serialization.Attributes;
23
using Newtonsoft.Json;
34
using Serilog.Ui.Core;
45
using System;
@@ -8,6 +9,7 @@
89
namespace Serilog.Ui.MongoDbProvider
910
{
1011
[BsonIgnoreExtraElements]
12+
[BsonDiscriminator(RootClass = true)]
1113
public class MongoDbLogModel
1214
{
1315
[BsonIgnore]
@@ -23,8 +25,10 @@ public class MongoDbLogModel
2325
[BsonDateTimeOptions(Kind = DateTimeKind.Local)]
2426
public DateTime UtcTimeStamp { get; set; }
2527

26-
public dynamic Exception { get; set; }
28+
[BsonElement("Exception")]
29+
public BsonDocument Exception { get; set; }
2730

31+
[BsonElement("Properties")]
2832
public object Properties { get; set; }
2933

3034
internal LogModel ToLogModel()
@@ -36,20 +40,18 @@ internal LogModel ToLogModel()
3640
Message = RenderedMessage,
3741
Timestamp = Timestamp ?? UtcTimeStamp,
3842
Exception = GetException(Exception),
39-
Properties = Newtonsoft.Json.JsonConvert.SerializeObject(Properties),
43+
Properties = JsonConvert.SerializeObject(Properties),
4044
PropertyType = "json"
4145
};
4246
}
4347

44-
private object GetException(dynamic exception)
48+
private string GetException(object exception)
4549
{
46-
if (exception == null || IsPropertyExist(Exception, "_csharpnull"))
50+
if (exception == null || IsPropertyExist(exception, "_csharpnull"))
4751
return null;
4852

49-
if (exception is string)
50-
return exception;
51-
52-
return Newtonsoft.Json.JsonConvert.SerializeObject(Exception, Formatting.Indented);
53+
var str = exception.ToJson();
54+
return str;
5355
}
5456

5557
private bool IsPropertyExist(dynamic obj, string name)

0 commit comments

Comments
 (0)