@@ -49,10 +49,10 @@ static async Task<SQSBatchResponse> Handler(SQSEvent ev, ILambdaContext context)
4949 UpdateLinkIndex ( linkIndex , linkReference , record , context ) ;
5050 processedMessageCount ++ ;
5151 }
52- catch ( Exception )
52+ catch ( Exception e )
5353 {
5454 //Add failed message identifier to the batchItemFailures list
55-
55+ context . Logger . LogWarning ( e , "Failed to process message {MessageId}" , message . MessageId ) ;
5656 batchItemFailures . Add ( new SQSBatchResponse . BatchItemFailure
5757 {
5858 ItemIdentifier = message . MessageId
@@ -74,26 +74,26 @@ static async Task<SQSBatchResponse> Handler(SQSEvent ev, ILambdaContext context)
7474 try
7575 {
7676 _ = await s3Client . PutObjectAsync ( putObjectRequest ) ;
77- context . Logger . LogInformation ( $ "Successfully updated { bucketName } /{ indexFile } .") ;
78- context . Logger . LogInformation ( $ "Processed { processedMessageCount } messages.") ;
77+ context . Logger . LogInformation ( "Successfully updated {bucketName}/{indexFile}." , bucketName , indexFile ) ;
78+ context . Logger . LogInformation ( "Processed {processedMessageCount} messages." , processedMessageCount ) ;
7979 var response = new SQSBatchResponse ( batchItemFailures ) ;
80- var jsonString = JsonSerializer . Serialize ( response , LinkIndexUpdaterSerializerContext . Default . SQSBatchResponse ) ;
8180 if ( batchItemFailures . Count > 0 )
8281 {
83- context . Logger . LogInformation ( $ "Failed to process { batchItemFailures . Count } messages. Returning them to the queue.") ;
84- context . Logger . LogInformation ( jsonString ) ;
82+ var jsonString = JsonSerializer . Serialize ( response , LinkIndexUpdaterSerializerContext . Default . SQSBatchResponse ) ;
83+ context . Logger . LogInformation ( "Failed to process {batchItemFailuresCount} messages. Returning them to the queue." , batchItemFailures . Count ) ;
84+ context . Logger . LogDebug ( jsonString ) ;
8585 }
8686
8787 return response ;
8888 }
8989 catch ( Exception ex )
9090 {
9191 // if we fail to update the object, we need to return all the messages
92- context . Logger . LogError ( $ "Failed to update { bucketName } /{ indexFile } . Returning all { ev . Records . Count } messages to the queue.") ;
92+ context . Logger . LogError ( "Failed to update {bucketName}/{indexFile}. Returning all {recordCount } messages to the queue." , bucketName , indexFile , ev . Records . Count ) ;
9393 context . Logger . LogError ( ex , ex . Message ) ;
9494 ev . Records . ForEach ( m =>
9595 {
96- context . Logger . LogInformation ( $ "Returning message { m . MessageId } to the queue.") ;
96+ context . Logger . LogInformation ( "Returning message {messageId } to the queue." , m . MessageId ) ;
9797 } ) ;
9898
9999 var response = new SQSBatchResponse ( ev . Records . Select ( r => new SQSBatchResponse . BatchItemFailure
@@ -110,7 +110,7 @@ static async Task<SQSBatchResponse> Handler(SQSEvent ev, ILambdaContext context)
110110{
111111 if ( string . IsNullOrEmpty ( message . Body ) )
112112 throw new Exception ( "No Body in SQS Message." ) ;
113- context . Logger . LogInformation ( $ "Received message { message . Body } " ) ;
113+ context . Logger . LogDebug ( "Received message {messageBody}" , message . Body ) ;
114114 var s3Event = JsonSerializer . Deserialize < S3EventNotification > ( message . Body , LinkIndexUpdaterSerializerContext . Default . S3EventNotification ) ;
115115 if ( s3Event ? . Records == null || s3Event . Records . Count == 0 )
116116 throw new Exception ( "Invalid S3 event message format" ) ;
@@ -119,15 +119,14 @@ await Parallel.ForEachAsync(s3Event.Records, async (record, ctx) =>
119119 {
120120 var s3Bucket = record . S3 . Bucket ;
121121 var s3Object = record . S3 . Obj ;
122- context . Logger . LogInformation ( $ "Get object { s3Object . Key } from bucket { s3Bucket . Name } " ) ;
122+ context . Logger . LogInformation ( "Get object {key } from bucket {bucketName}" , s3Object . Key , s3Bucket . Name ) ;
123123 var getObjectResponse = await s3Client . GetObjectAsync ( s3Bucket . Name , s3Object . Key , ctx ) ;
124124 await using var stream = getObjectResponse . ResponseStream ;
125- context . Logger . LogInformation ( $ "Deserializing link reference from { s3Object . Key } " ) ;
125+ context . Logger . LogInformation ( "Deserializing link reference from {key}" , s3Object . Key ) ;
126126 var linkReference = LinkReference . Deserialize ( stream ) ;
127- context . Logger . LogInformation ( $ "Link reference deserialized: { linkReference } ") ;
128127 linkReferences . Add ( ( record , linkReference ) ) ;
129128 } ) ;
130- context . Logger . LogInformation ( $ "Deserialized { linkReferences . Count } link references from S3 event") ;
129+ context . Logger . LogInformation ( "Deserialized {linkReferenceCount } link references from S3 event" , linkReferences . Count ) ;
131130 return linkReferences ;
132131}
133132
@@ -152,29 +151,23 @@ static void UpdateLinkIndex(LinkIndex linkIndex, LinkReference linkReference, S3
152151 UpdatedAt = s3EventRecord . EventTime ,
153152 GitReference = linkReference . Origin . Ref
154153 } ;
155-
156- if ( repository == "docs-content" )
157- {
158- throw new Exception ( "This is a test exception" ) ;
159- }
160-
161154 if ( linkIndex . Repositories . TryGetValue ( repository , out var existingEntry ) )
162155 {
163156 var newEntryIsNewer = DateTime . Compare ( newEntry . UpdatedAt , existingEntry [ branch ] . UpdatedAt ) > 0 ;
164157 if ( newEntryIsNewer )
165158 {
166159 existingEntry [ branch ] = newEntry ;
167- context . Logger . LogInformation ( $ "Updated existing entry for { repository } @{ branch } ") ;
160+ context . Logger . LogInformation ( "Updated existing entry for {repository}@{branch}" , repository , branch ) ;
168161 }
169162 else
170- context . Logger . LogInformation ( $ "Skipping update for { repository } @{ branch } because the existing entry is newer") ;
163+ context . Logger . LogInformation ( "Skipping update for {repository}@{branch} because the existing entry is newer" , repository , branch ) ;
171164 }
172165 else
173166 {
174167 linkIndex . Repositories . Add ( repository , new Dictionary < string , LinkIndexEntry >
175168 {
176169 { branch , newEntry }
177170 } ) ;
178- context . Logger . LogInformation ( $ "Added new entry for { repository } @{ branch } ") ;
171+ context . Logger . LogInformation ( "Added new entry for {repository}@{branch}" , repository , branch ) ;
179172 }
180173}
0 commit comments