@@ -25,8 +25,8 @@ static async Task Main()
2525 try
2626 {
2727 IConfigurationRoot configuration = new ConfigurationBuilder ( )
28- . AddJsonFile ( "AppSettings.json" )
29- . Build ( ) ;
28+ . AddJsonFile ( "AppSettings.json" )
29+ . Build ( ) ;
3030
3131 string endpoint = configuration [ "CosmosDBEndPointUrl" ] ;
3232 if ( string . IsNullOrEmpty ( endpoint ) )
@@ -52,12 +52,16 @@ static async Task Main()
5252 serviceVersion : "1.0.0" ) ;
5353
5454 // Set up logging to forward logs to chosen exporter
55- using ILoggerFactory loggerFactory = LoggerFactory . Create ( builder => builder . AddOpenTelemetry ( options =>
56- {
57- options . IncludeFormattedMessage = true ;
58- options . SetResourceBuilder ( resource ) ;
59- options . AddAzureMonitorLogExporter ( o => o . ConnectionString = aiConnectionString ) ; // Set up exporter of your choice
60- } ) ) ;
55+ using ILoggerFactory loggerFactory
56+ = LoggerFactory . Create ( builder => builder
57+ . AddConfiguration ( configuration . GetSection ( "Logging" ) )
58+ . AddOpenTelemetry ( options =>
59+ {
60+ options . IncludeFormattedMessage = true ;
61+ options . SetResourceBuilder ( resource ) ;
62+ options . AddAzureMonitorLogExporter ( o => o . ConnectionString = aiConnectionString ) ; // Set up exporter of your choice
63+ } ) ) ;
64+ /*.AddFilter(level => level == LogLevel.Error) // Filter is irrespective of event type or event name*/
6165
6266 AzureEventSourceLogForwarder logforwader = new AzureEventSourceLogForwarder ( loggerFactory ) ;
6367 logforwader . Start ( ) ;
@@ -76,6 +80,7 @@ static async Task Main()
7680 {
7781 IsDistributedTracingEnabled = true // Defaults to true, set to false to disable
7882 } ;
83+
7984 // </EnableDistributedTracing>
8085 using ( CosmosClient client = new CosmosClient ( endpoint , authKey , options ) )
8186 {
@@ -88,7 +93,6 @@ static async Task Main()
8893
8994 await Program . RunCrudDemo ( container ) ;
9095 }
91-
9296 }
9397 finally
9498 {
@@ -116,6 +120,15 @@ public static async Task RunCrudDemo(Container container)
116120 Console . WriteLine ( $ "Read document with id: { i } ") ;
117121 }
118122
123+ try
124+ {
125+ await container . ReadItemAsync < Item > ( $ "random key", new PartitionKey ( $ "random partition") ) ;
126+ }
127+ catch ( Exception )
128+ {
129+ Console . WriteLine ( "Generate exception by reading an invalid key" ) ;
130+ }
131+
119132 for ( int i = 1 ; i <= 5 ; i ++ )
120133 {
121134 await container . ReplaceItemAsync ( new Item { Id = $ "{ i } ", Status = "updated" } , $ "{ i } ", new PartitionKey ( $ "{ i } ") ) ;
0 commit comments