@@ -34,72 +34,70 @@ public ArangoSerilogSink(
3434 LoggingRenderStrategy renderMessage = LoggingRenderStrategy . RenderMessage ,
3535 bool indexLevel = false ,
3636 bool indexTimestamp = false ,
37- bool indexTemplate = false ) : this ( arango , database , collection )
37+ bool indexTemplate = false )
3838 {
39+ _arango = arango ;
40+ _database = database ;
41+ _collection = collection ;
3942 _renderMessage = renderMessage ;
4043 _indexLevel = indexLevel ;
4144 _indexTimestamp = indexTimestamp ;
4245 _indexTemplate = indexTemplate ;
46+
47+ Setup ( ) . GetAwaiter ( ) . GetResult ( ) ;
4348 }
4449
45-
46- public ArangoSerilogSink (
47- IArangoContext arango ,
48- string database = "logs" ,
49- string collection = "logs" )
50+ private async Task Setup ( )
5051 {
51- _arango = arango ;
52- _database = database ;
53- _collection = collection ;
54-
5552 try
5653 {
57- if ( ! _arango . Database . ExistAsync ( _database ) . AsTask ( ) . GetAwaiter ( ) . GetResult ( ) )
58- _arango . Database . CreateAsync ( _database ) . AsTask ( ) . Wait ( ) ;
59-
60- var indexes = _arango . Index . ListAsync ( _database , _collection )
61- . AsTask ( ) . GetAwaiter ( ) . GetResult ( ) ;
54+ if ( ! await _arango . Database . ExistAsync ( _database ) )
55+ {
56+ await _arango . Database . CreateAsync ( _database ) ;
57+ }
6258
63- if ( ! _arango . Collection . ExistAsync ( _database , collection ) . AsTask ( ) . GetAwaiter ( ) . GetResult ( ) )
59+ if ( ! await _arango . Collection . ExistAsync ( _database , _collection ) )
6460 {
65- _arango . Collection . CreateAsync ( _database , new ArangoCollection
61+ await _arango . Collection . CreateAsync ( _database , new ArangoCollection
6662 {
6763 Name = _collection ,
6864 KeyOptions = new ArangoKeyOptions
6965 {
7066 Type = ArangoKeyType . Padded
7167 }
72- } ) . AsTask ( ) . Wait ( ) ;
68+ } ) ;
7369 }
7470
75- if ( _indexLevel &&
76- indexes . Any ( x => x . Name == nameof ( LogEventEntity . Level ) ) )
71+ var indexes = ( await _arango . Index . ListAsync ( _database , _collection ) ) . ToList ( ) ;
72+
73+ if ( _indexLevel && indexes . All ( x => x . Name != nameof ( LogEventEntity . Level ) ) )
7774 {
78- _arango . Index . CreateAsync ( _database , _collection , new ArangoIndex
75+ await _arango . Index . CreateAsync ( _database , _collection , new ArangoIndex
7976 {
8077 Type = ArangoIndexType . Persistent ,
81- Name = nameof ( LogEventEntity . Level )
82- } ) . AsTask ( ) . Wait ( ) ;
78+ Name = nameof ( LogEventEntity . Level ) ,
79+ Fields = [ nameof ( LogEventEntity . Level ) ]
80+ } ) ;
8381 }
8482
85- if ( _indexTimestamp &&
86- indexes . Any ( x => x . Name == nameof ( LogEventEntity . Timestamp ) ) )
83+ if ( _indexTimestamp && indexes . All ( x => x . Name != nameof ( LogEventEntity . Timestamp ) ) )
8784 {
88- _arango . Index . CreateAsync ( _database , _collection , new ArangoIndex
85+ await _arango . Index . CreateAsync ( _database , _collection , new ArangoIndex
8986 {
9087 Type = ArangoIndexType . Persistent ,
91- Name = nameof ( LogEventEntity . Timestamp )
92- } ) . AsTask ( ) . Wait ( ) ;
88+ Name = nameof ( LogEventEntity . Timestamp ) ,
89+ Fields = [ nameof ( LogEventEntity . Timestamp ) ]
90+ } ) ;
9391 }
94-
95- if ( _indexTemplate &&
96- indexes . Any ( x => x . Name == nameof ( LogEventEntity . MessageTemplate ) ) )
92+
93+ if ( _indexTemplate && indexes . All ( x => x . Name != nameof ( LogEventEntity . MessageTemplate ) ) )
9794 {
98- _arango . Index . CreateAsync ( _database , _collection , new ArangoIndex
95+ await _arango . Index . CreateAsync ( _database , _collection , new ArangoIndex
9996 {
10097 Type = ArangoIndexType . Persistent ,
101- Name = nameof ( LogEventEntity . MessageTemplate )
102- } ) . AsTask ( ) . Wait ( ) ;
98+ Name = nameof ( LogEventEntity . MessageTemplate ) ,
99+ Fields = [ nameof ( LogEventEntity . MessageTemplate ) ]
100+ } ) ;
103101 }
104102 }
105103 catch ( Exception )
@@ -114,7 +112,7 @@ public async Task EmitBatchAsync(IEnumerable<LogEvent> events)
114112 {
115113 var renderMessage = _renderMessage . HasFlag ( LoggingRenderStrategy . RenderMessage ) ;
116114 var storeTemplate = _renderMessage . HasFlag ( LoggingRenderStrategy . StoreTemplate ) ;
117-
115+
118116 await _arango . Document . CreateManyAsync ( _database , _collection , events . Select ( x => new LogEventEntity
119117 {
120118 Level = x . Level . ToString ( ) ,
0 commit comments