Skip to content

logging changes #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion samples/FunctionApp/Function4/Function4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public static class Function4
[FunctionName("Function4")]
public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req, FunctionContext executionContext)
{
var logger = executionContext.Logger;
var logger = executionContext.GetLogger("FunctionApp.Function4");

logger.LogInformation("message logged");
var response = new HttpResponseData(HttpStatusCode.OK);
var headers = new Dictionary<string, string>();
Expand Down
9 changes: 5 additions & 4 deletions samples/FunctionApp/Function5/Function5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ namespace FunctionApp
public class Function5
{
private readonly IHttpResponderService _responderService;
private readonly ILogger<Function5> _logger;

public Function5(IHttpResponderService responderService)
public Function5(IHttpResponderService responderService, ILogger<Function5> logger)
{
_responderService = responderService;
_logger = logger;
}

[FunctionName(nameof(Function5))]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req, FunctionContext executionContext)
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req)
{
var logger = executionContext.Logger;
logger.LogInformation("message logged");
_logger.LogInformation("message logged");

return _responderService.ProcessRequest(req);
}
Expand Down
2 changes: 1 addition & 1 deletion samples/SampleApp/Blob/BlobFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void Run(
[BlobInput("test-samples-input/sample1.txt", Connection = "AzureWebJobsStorage")] string myBlob,
FunctionContext context)
{
var logger = context.Logger;
var logger = context.GetLogger("BlobFunction");
logger.LogInformation($"Triggered Item = {myTriggerItem}");
logger.LogInformation($"Input Item = {myBlob}");

Expand Down
4 changes: 2 additions & 2 deletions samples/SampleApp/CosmosDB/CosmosDBFunction.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

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

if (input != null && input.Any())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
using Microsoft.Azure.Functions.Worker.Extensions.Http;
using Microsoft.Azure.Functions.Worker.Pipeline;
using Microsoft.Extensions.Logging;

namespace SampleApp
{
public class DependencyInjectionFunction
{
private readonly IHttpResponderService _responderService;
private readonly ILogger<DependencyInjectionFunction> _logger;

public DependencyInjectionFunction(IHttpResponderService responderService)
public DependencyInjectionFunction(IHttpResponderService responderService, ILogger<DependencyInjectionFunction> logger)
{
_responderService = responderService;
_logger = logger;
}

[FunctionName(nameof(DependencyInjectionFunction))]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req,
FunctionContext executionContext)
FunctionContext context)
{
var logger = executionContext.Logger;
logger.LogInformation("message logged");
_logger.LogInformation("message logged");

return _responderService.ProcessRequest(req);
}
Expand Down
4 changes: 2 additions & 2 deletions samples/SampleApp/EventGrid/EventGridFunction.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

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

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

Expand Down
4 changes: 2 additions & 2 deletions samples/SampleApp/EventHubs/EventHubsFunction.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
using Microsoft.Azure.Functions.Worker.Extensions.EventHubs;
Expand All @@ -16,7 +16,7 @@ public static class EventHubsFunction
public static void Run([EventHubTrigger("src", Connection = "EventHubConnectionAppSetting")] string input,
FunctionContext context)
{
var logger = context.Logger;
var logger = context.GetLogger("EventHubsFunction");

logger.LogInformation(input);

Expand Down
3 changes: 1 addition & 2 deletions samples/SampleApp/Http/HttpFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
using Microsoft.Azure.Functions.Worker.Extensions.Http;
using Microsoft.Azure.Functions.Worker.Pipeline;
using Microsoft.Extensions.Logging;

namespace SampleApp
Expand All @@ -17,7 +16,7 @@ public static class HttpFunction
public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req,
FunctionContext executionContext)
{
var logger = executionContext.Logger;
var logger = executionContext.GetLogger("HttpFunction");
logger.LogInformation("message logged");
var response = new HttpResponseData(HttpStatusCode.OK);
var headers = new Dictionary<string, string>();
Expand Down
4 changes: 2 additions & 2 deletions samples/SampleApp/Kafka/KafkaFunction.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

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

logger.LogInformation(input);

Expand Down
2 changes: 1 addition & 1 deletion samples/SampleApp/Queue/QueueFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class QueueFunction
public static void Run([QueueTrigger("functionstesting2", Connection = "AzureWebJobsStorage")] Book myQueueItem,
FunctionContext context)
{
var logger = context.Logger;
var logger = context.GetLogger("QueueFunction");
logger.LogInformation($"Book name = {myQueueItem.Name}");

// Queue Output
Expand Down
4 changes: 2 additions & 2 deletions samples/SampleApp/RabbitMQ/RabbitMQFunction.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
using Microsoft.Azure.Functions.Worker.Extensions.RabbitMQ;
Expand All @@ -16,7 +16,7 @@ public static class RabbitMQFunction
public static void Run([RabbitMQTrigger("queue", ConnectionStringSetting = "rabbitMQConnectionAppSetting")] string item,
FunctionContext context)
{
var logger = context.Logger;
var logger = context.GetLogger("RabbitMQFunction");

logger.LogInformation(item);

Expand Down
4 changes: 2 additions & 2 deletions samples/SampleApp/ServiceBus/ServiceBusFunction.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
using Microsoft.Azure.Functions.Worker.Extensions.ServiceBus;
Expand All @@ -16,7 +16,7 @@ public static class ServiceBusFunction
public static void Run([ServiceBusTrigger("queue", Connection = "ServiceBusConnection")] string item,
FunctionContext context)
{
var logger = context.Logger;
var logger = context.GetLogger("ServiceBusFunction");

logger.LogInformation(item);

Expand Down
4 changes: 2 additions & 2 deletions samples/SampleApp/SignalR/SignalRFunction.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
using Microsoft.Azure.Functions.Worker.Extensions.SignalRService;
Expand All @@ -18,7 +18,7 @@ public static class SignalRFunction
[SignalRConnectionInfoInput(HubName = "chat")] MyConnectionInfo connectionInfo,
FunctionContext context)
{
var logger = context.Logger;
var logger = context.GetLogger("SignalRFunction");

logger.LogInformation(item);
logger.LogInformation($"Connection URL = {connectionInfo.Url}");
Expand Down
4 changes: 2 additions & 2 deletions samples/SampleApp/Table/TableFunction.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

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

logger.LogInformation(tableItem.ToString());

Expand Down
2 changes: 1 addition & 1 deletion samples/SampleApp/Timer/TimerFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class TimerFunction
public static void Run([TimerTrigger("0 */5 * * * *")] MyInfo timerInfo,
FunctionContext context)
{
var logger = context.Logger;
var logger = context.GetLogger("TimerFunction");
logger.LogInformation($"Function Ran. Next timer schedule = {timerInfo.ScheduleStatus.Next}");
}
}
Expand Down
2 changes: 1 addition & 1 deletion samples/SampleApp/Warmup/Warmup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class Warmup
[FunctionName("Warmup")]
public static void Run([WarmupTrigger] object _, FunctionContext context)
{
var logger = context.Logger;
var logger = context.GetLogger("Warmup");

logger.LogInformation("Function App instance is now warm!");
}
Expand Down
23 changes: 23 additions & 0 deletions src/DotNetWorker/Broker/FunctionBroker.Log.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using Microsoft.Extensions.Logging;

namespace Microsoft.Azure.Functions.Worker
{
internal partial class FunctionBroker
{
private static class Log
{
private static readonly Action<ILogger, string, string, Exception?> _functionDefinitionCreated =
WorkerMessage.Define<string, string>(LogLevel.Trace, new EventId(1, nameof(FunctionDefinitionCreated)),
"Function definition for '{functionName}' created with id '{functionid}'.");

public static void FunctionDefinitionCreated(ILogger<FunctionBroker> logger, FunctionDefinition functionDefinition)
{
_functionDefinitionCreated(logger, functionDefinition.Metadata.Name, functionDefinition.Metadata.FunctionId, null);
}
}
}
}
Loading