Created
October 1, 2021 22:41
-
-
Save loic-sharma/50c2aec0dff3708c5be9f404c3b97690 to your computer and use it in GitHub Desktop.
AzFuncLogging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Azure.Functions.Worker; | |
using Microsoft.Azure.Functions.Worker.Http; | |
using Microsoft.Extensions.Logging; | |
using System.Net; | |
namespace AzFuncLogging | |
{ | |
public class Function1 | |
{ | |
private readonly ILogger<Function1> _logger; | |
public Function1(ILogger<Function1> logger) | |
{ | |
_logger = logger; | |
} | |
[Function("Function1")] | |
public HttpResponseData Run( | |
[HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, | |
FunctionContext executionContext) | |
{ | |
var logger = executionContext.GetLogger("Function1"); | |
logger.LogInformation("Foo"); | |
_logger.LogInformation("Bar"); | |
var response = req.CreateResponse(HttpStatusCode.OK); | |
response.Headers.Add("Content-Type", "text/plain; charset=utf-8"); | |
response.WriteString("Hello hello"); | |
return response; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "2.0", | |
"logging": { | |
"applicationInsights": { | |
"samplingSettings": { | |
"isEnabled": true, | |
"excludedTypes": "Request" | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Azure.Functions.Worker.Configuration; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.Hosting; | |
using System.Threading.Tasks; | |
namespace AzFuncLogging | |
{ | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var host = new HostBuilder() | |
.ConfigureFunctionsWorkerDefaults() | |
.Build(); | |
host.Run(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment