@@ -67,14 +67,24 @@ public static async Task GenerateTemplates(
67
67
68
68
// Get all Apis that will be extracted
69
69
List < string > apisToExtract = new List < string > ( ) ;
70
- if ( singleApiName != null ) {
70
+ if ( singleApiName != null )
71
+ {
71
72
apisToExtract . Add ( singleApiName ) ;
72
- } else if ( multipleApiNames != null ) {
73
+ }
74
+ else if ( multipleApiNames != null )
75
+ {
73
76
apisToExtract . AddRange ( multipleApiNames ) ;
74
- } else {
77
+ }
78
+ else
79
+ {
75
80
List < string > allApis = await apiExtractor . GetAllAPINamesAsync ( exc . sourceApimName , exc . resourceGroup ) ;
76
81
apisToExtract . AddRange ( allApis ) ;
77
82
}
83
+ Dictionary < string , Dictionary < string , string > > apiLoggerId = null ;
84
+ if ( exc . paramApiLoggerId )
85
+ {
86
+ apiLoggerId = await GetAllReferencedLoggers ( apisToExtract , exc ) ;
87
+ }
78
88
79
89
// extract templates from apim service
80
90
Template globalServicePolicyTemplate = await policyExtractor . GenerateGlobalServicePolicyTemplateAsync ( sourceApim , resourceGroup , policyXMLBaseUrl , policyXMLSasToken , dirName ) ;
@@ -85,7 +95,7 @@ public static async Task GenerateTemplates(
85
95
List < TemplateResource > apiTemplateResources = apiTemplate . resources . ToList ( ) ;
86
96
Template apiVersionSetTemplate = await apiVersionSetExtractor . GenerateAPIVersionSetsARMTemplateAsync ( sourceApim , resourceGroup , singleApiName , apiTemplateResources , policyXMLBaseUrl , policyXMLSasToken ) ;
87
97
Template authorizationServerTemplate = await authorizationServerExtractor . GenerateAuthorizationServersARMTemplateAsync ( sourceApim , resourceGroup , singleApiName , apiTemplateResources , policyXMLBaseUrl , policyXMLSasToken ) ;
88
- Template loggerTemplate = await loggerExtractor . GenerateLoggerTemplateAsync ( sourceApim , resourceGroup , singleApiName , apiTemplateResources , policyXMLBaseUrl , policyXMLSasToken ) ;
98
+ Template loggerTemplate = await loggerExtractor . GenerateLoggerTemplateAsync ( exc , singleApiName , apiTemplateResources , apiLoggerId ) ;
89
99
Template productTemplate = await productExtractor . GenerateProductsARMTemplateAsync ( sourceApim , resourceGroup , singleApiName , apiTemplateResources , policyXMLBaseUrl , policyXMLSasToken , dirName ) ;
90
100
List < TemplateResource > productTemplateResources = productTemplate . resources . ToList ( ) ;
91
101
Template namedValueTemplate = await propertyExtractor . GenerateNamedValuesTemplateAsync ( singleApiName , apiTemplateResources , exc ) ;
@@ -94,7 +104,7 @@ public static async Task GenerateTemplates(
94
104
Template backendTemplate = await backendExtractor . GenerateBackendsARMTemplateAsync ( sourceApim , resourceGroup , singleApiName , apiTemplateResources , namedValueResources , policyXMLBaseUrl , policyXMLSasToken ) ;
95
105
96
106
// create parameters file
97
- Template templateParameters = await masterTemplateExtractor . CreateMasterTemplateParameterValues ( apisToExtract , exc ) ;
107
+ Template templateParameters = await masterTemplateExtractor . CreateMasterTemplateParameterValues ( apisToExtract , exc , apiLoggerId ) ;
98
108
99
109
// write templates to output file location
100
110
string apiFileName = fileNameGenerator . GenerateExtractorAPIFileName ( singleApiName , sourceApim ) ;
@@ -330,5 +340,29 @@ public static async Task<Dictionary<string, List<string>>> GetAllAPIsDictionary(
330
340
}
331
341
return apiDictionary ;
332
342
}
343
+
344
+ // this function generate all reference loggers in all extracted apis
345
+ public static async Task < Dictionary < string , Dictionary < string , string > > > GetAllReferencedLoggers ( List < string > apisToExtract , Extractor exc )
346
+ {
347
+ Dictionary < string , Dictionary < string , string > > ApiLoggerId = new Dictionary < string , Dictionary < string , string > > ( ) ;
348
+ APIExtractor apiExc = new APIExtractor ( new FileWriter ( ) ) ;
349
+ foreach ( string curApiName in apisToExtract )
350
+ {
351
+ Dictionary < string , string > loggerIds = new Dictionary < string , string > ( ) ;
352
+ string diagnostics = await apiExc . GetAPIDiagnosticsAsync ( exc . sourceApimName , exc . resourceGroup , curApiName ) ;
353
+ JObject oDiagnostics = JObject . Parse ( diagnostics ) ;
354
+ foreach ( var diagnostic in oDiagnostics [ "value" ] )
355
+ {
356
+ string diagnosticName = ( ( JValue ) diagnostic [ "name" ] ) . Value . ToString ( ) ;
357
+ string loggerId = ( ( JValue ) diagnostic [ "properties" ] [ "loggerId" ] ) . Value . ToString ( ) ;
358
+ loggerIds . Add ( ExtractorUtils . GenValidParamName ( diagnosticName , "Diagnostic" ) , loggerId ) ;
359
+ }
360
+ if ( loggerIds . Count != 0 )
361
+ {
362
+ ApiLoggerId . Add ( ExtractorUtils . GenValidParamName ( curApiName , "Api" ) , loggerIds ) ;
363
+ }
364
+ }
365
+ return ApiLoggerId ;
366
+ }
333
367
}
334
368
}
0 commit comments