Skip to content

Commit 6292abb

Browse files
authored
removing Logger from FunctionContext, adding WorkerMessage internally (#123)
1 parent 418b3b9 commit 6292abb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+798
-141
lines changed

samples/FunctionApp/Function4/Function4.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public static class Function4
1717
[FunctionName("Function4")]
1818
public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req, FunctionContext executionContext)
1919
{
20-
var logger = executionContext.Logger;
20+
var logger = executionContext.GetLogger("FunctionApp.Function4");
21+
2122
logger.LogInformation("message logged");
2223
var response = new HttpResponseData(HttpStatusCode.OK);
2324
var headers = new Dictionary<string, string>();

samples/FunctionApp/Function5/Function5.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@ namespace FunctionApp
1414
public class Function5
1515
{
1616
private readonly IHttpResponderService _responderService;
17+
private readonly ILogger<Function5> _logger;
1718

18-
public Function5(IHttpResponderService responderService)
19+
public Function5(IHttpResponderService responderService, ILogger<Function5> logger)
1920
{
2021
_responderService = responderService;
22+
_logger = logger;
2123
}
2224

2325
[FunctionName(nameof(Function5))]
24-
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req, FunctionContext executionContext)
26+
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req)
2527
{
26-
var logger = executionContext.Logger;
27-
logger.LogInformation("message logged");
28+
_logger.LogInformation("message logged");
2829

2930
return _responderService.ProcessRequest(req);
3031
}

samples/SampleApp/Blob/BlobFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static void Run(
1717
[BlobInput("test-samples-input/sample1.txt", Connection = "AzureWebJobsStorage")] string myBlob,
1818
FunctionContext context)
1919
{
20-
var logger = context.Logger;
20+
var logger = context.GetLogger("BlobFunction");
2121
logger.LogInformation($"Triggered Item = {myTriggerItem}");
2222
logger.LogInformation($"Input Item = {myBlob}");
2323

samples/SampleApp/CosmosDB/CosmosDBFunction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
using System.Collections.Generic;
4+
using System.Collections.Generic;
55
using System.Linq;
66
using Microsoft.Azure.Functions.Worker;
77
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
@@ -19,7 +19,7 @@ public static void Run(
1919
LeaseCollectionName = "leases", CreateLeaseCollectionIfNotExists = true)] IReadOnlyList<MyDocument> input,
2020
FunctionContext context)
2121
{
22-
var logger = context.Logger;
22+
var logger = context.GetLogger("CosmosDBFunction");
2323

2424
if (input != null && input.Any())
2525
{

samples/SampleApp/DependencyInjection/DependencyInjectionFunction.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@
66
using Microsoft.Azure.Functions.Worker;
77
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
88
using Microsoft.Azure.Functions.Worker.Extensions.Http;
9-
using Microsoft.Azure.Functions.Worker.Pipeline;
109
using Microsoft.Extensions.Logging;
1110

1211
namespace SampleApp
1312
{
1413
public class DependencyInjectionFunction
1514
{
1615
private readonly IHttpResponderService _responderService;
16+
private readonly ILogger<DependencyInjectionFunction> _logger;
1717

18-
public DependencyInjectionFunction(IHttpResponderService responderService)
18+
public DependencyInjectionFunction(IHttpResponderService responderService, ILogger<DependencyInjectionFunction> logger)
1919
{
2020
_responderService = responderService;
21+
_logger = logger;
2122
}
2223

2324
[FunctionName(nameof(DependencyInjectionFunction))]
2425
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req,
25-
FunctionContext executionContext)
26+
FunctionContext context)
2627
{
27-
var logger = executionContext.Logger;
28-
logger.LogInformation("message logged");
28+
_logger.LogInformation("message logged");
2929

3030
return _responderService.ProcessRequest(req);
3131
}

samples/SampleApp/EventGrid/EventGridFunction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
using System.Collections.Generic;
4+
using System.Collections.Generic;
55
using Microsoft.Azure.Functions.Worker;
66
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
77
using Microsoft.Azure.Functions.Worker.Extensions.EventGrid;
@@ -15,7 +15,7 @@ public static class EventGridFunction
1515
[EventGridOutput("output", TopicEndpointUri = "MyEventGridTopicUriSetting", TopicKeySetting = "MyEventGridTopicKeySetting")]
1616
public static void Run([EventGridTrigger] MyEventType input, FunctionContext context)
1717
{
18-
var logger = context.Logger;
18+
var logger = context.GetLogger("EventGridFunction");
1919

2020
logger.LogInformation(input.Data.ToString());
2121

samples/SampleApp/EventHubs/EventHubsFunction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
using System;
4+
using System;
55
using Microsoft.Azure.Functions.Worker;
66
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
77
using Microsoft.Azure.Functions.Worker.Extensions.EventHubs;
@@ -16,7 +16,7 @@ public static class EventHubsFunction
1616
public static void Run([EventHubTrigger("src", Connection = "EventHubConnectionAppSetting")] string input,
1717
FunctionContext context)
1818
{
19-
var logger = context.Logger;
19+
var logger = context.GetLogger("EventHubsFunction");
2020

2121
logger.LogInformation(input);
2222

samples/SampleApp/Http/HttpFunction.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Microsoft.Azure.Functions.Worker;
77
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
88
using Microsoft.Azure.Functions.Worker.Extensions.Http;
9-
using Microsoft.Azure.Functions.Worker.Pipeline;
109
using Microsoft.Extensions.Logging;
1110

1211
namespace SampleApp
@@ -17,7 +16,7 @@ public static class HttpFunction
1716
public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req,
1817
FunctionContext executionContext)
1918
{
20-
var logger = executionContext.Logger;
19+
var logger = executionContext.GetLogger("HttpFunction");
2120
logger.LogInformation("message logged");
2221
var response = new HttpResponseData(HttpStatusCode.OK);
2322
var headers = new Dictionary<string, string>();

samples/SampleApp/Kafka/KafkaFunction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
using System;
4+
using System;
55
using Microsoft.Azure.Functions.Worker;
66
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
77
using Microsoft.Azure.Functions.Worker.Extensions.Kafka;
@@ -17,7 +17,7 @@ public static void Run([KafkaTrigger("LocalBroker", "stringTopicTenPartitions",
1717
ConsumerGroup = "$Default", AuthenticationMode = BrokerAuthenticationMode.Plain)] string input,
1818
FunctionContext context)
1919
{
20-
var logger = context.Logger;
20+
var logger = context.GetLogger("KafkaFunction");
2121

2222
logger.LogInformation(input);
2323

samples/SampleApp/Queue/QueueFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class QueueFunction
1515
public static void Run([QueueTrigger("functionstesting2", Connection = "AzureWebJobsStorage")] Book myQueueItem,
1616
FunctionContext context)
1717
{
18-
var logger = context.Logger;
18+
var logger = context.GetLogger("QueueFunction");
1919
logger.LogInformation($"Book name = {myQueueItem.Name}");
2020

2121
// Queue Output

samples/SampleApp/RabbitMQ/RabbitMQFunction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
using System;
4+
using System;
55
using Microsoft.Azure.Functions.Worker;
66
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
77
using Microsoft.Azure.Functions.Worker.Extensions.RabbitMQ;
@@ -16,7 +16,7 @@ public static class RabbitMQFunction
1616
public static void Run([RabbitMQTrigger("queue", ConnectionStringSetting = "rabbitMQConnectionAppSetting")] string item,
1717
FunctionContext context)
1818
{
19-
var logger = context.Logger;
19+
var logger = context.GetLogger("RabbitMQFunction");
2020

2121
logger.LogInformation(item);
2222

samples/SampleApp/ServiceBus/ServiceBusFunction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
using System;
4+
using System;
55
using Microsoft.Azure.Functions.Worker;
66
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
77
using Microsoft.Azure.Functions.Worker.Extensions.ServiceBus;
@@ -16,7 +16,7 @@ public static class ServiceBusFunction
1616
public static void Run([ServiceBusTrigger("queue", Connection = "ServiceBusConnection")] string item,
1717
FunctionContext context)
1818
{
19-
var logger = context.Logger;
19+
var logger = context.GetLogger("ServiceBusFunction");
2020

2121
logger.LogInformation(item);
2222

samples/SampleApp/SignalR/SignalRFunction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
using System;
4+
using System;
55
using Microsoft.Azure.Functions.Worker;
66
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
77
using Microsoft.Azure.Functions.Worker.Extensions.SignalRService;
@@ -18,7 +18,7 @@ public static class SignalRFunction
1818
[SignalRConnectionInfoInput(HubName = "chat")] MyConnectionInfo connectionInfo,
1919
FunctionContext context)
2020
{
21-
var logger = context.Logger;
21+
var logger = context.GetLogger("SignalRFunction");
2222

2323
logger.LogInformation(item);
2424
logger.LogInformation($"Connection URL = {connectionInfo.Url}");

samples/SampleApp/Table/TableFunction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
using System;
4+
using System;
55
using Microsoft.Azure.Functions.Worker;
66
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
77
using Microsoft.Azure.Functions.Worker.Extensions.Storage;
@@ -18,7 +18,7 @@ public static void Run([QueueTrigger("table-items")] string input,
1818
[TableInput("MyTable", "MyPartition", "{queueTrigger}")] JObject tableItem,
1919
FunctionContext context)
2020
{
21-
var logger = context.Logger;
21+
var logger = context.GetLogger("TableFunction");
2222

2323
logger.LogInformation(tableItem.ToString());
2424

samples/SampleApp/Timer/TimerFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class TimerFunction
1515
public static void Run([TimerTrigger("0 */5 * * * *")] MyInfo timerInfo,
1616
FunctionContext context)
1717
{
18-
var logger = context.Logger;
18+
var logger = context.GetLogger("TimerFunction");
1919
logger.LogInformation($"Function Ran. Next timer schedule = {timerInfo.ScheduleStatus.Next}");
2020
}
2121
}

samples/SampleApp/Warmup/Warmup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static class Warmup
1313
[FunctionName("Warmup")]
1414
public static void Run([WarmupTrigger] object _, FunctionContext context)
1515
{
16-
var logger = context.Logger;
16+
var logger = context.GetLogger("Warmup");
1717

1818
logger.LogInformation("Function App instance is now warm!");
1919
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System;
5+
using Microsoft.Extensions.Logging;
6+
7+
namespace Microsoft.Azure.Functions.Worker
8+
{
9+
internal partial class FunctionBroker
10+
{
11+
private static class Log
12+
{
13+
private static readonly Action<ILogger, string, string, Exception?> _functionDefinitionCreated =
14+
WorkerMessage.Define<string, string>(LogLevel.Trace, new EventId(1, nameof(FunctionDefinitionCreated)),
15+
"Function definition for '{functionName}' created with id '{functionid}'.");
16+
17+
public static void FunctionDefinitionCreated(ILogger<FunctionBroker> logger, FunctionDefinition functionDefinition)
18+
{
19+
_functionDefinitionCreated(logger, functionDefinition.Metadata.Name, functionDefinition.Metadata.FunctionId, null);
20+
}
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)