Configure LogLevel of Azure Function using environment variables
up vote
0
down vote
favorite
As per the Azure documentation, Functions V2 uses the .NET Core logging filter hierarchy for configuration.
In the following example, an instance of ILogger is injected into the Run method of the function.
[FunctionName("MyFunction")]
public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger logger, ExecutionContext executionContext)
{
logger.LogInformation("I don't want to see this in production!"));
}
When inspecting the ILogger object, each LoggerInformation element has MinLevel of null which seems to log all levels.
In production, I only want to log at the Error level. I would like to be able to configure this using an environment variable but I cannot find any documentation which explains how to achieve this. I have tried adding the following environment variable to no effect:
"logging__logLevel__Default: "Error"
azure asp.net-core azure-functions
add a comment |
up vote
0
down vote
favorite
As per the Azure documentation, Functions V2 uses the .NET Core logging filter hierarchy for configuration.
In the following example, an instance of ILogger is injected into the Run method of the function.
[FunctionName("MyFunction")]
public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger logger, ExecutionContext executionContext)
{
logger.LogInformation("I don't want to see this in production!"));
}
When inspecting the ILogger object, each LoggerInformation element has MinLevel of null which seems to log all levels.
In production, I only want to log at the Error level. I would like to be able to configure this using an environment variable but I cannot find any documentation which explains how to achieve this. I have tried adding the following environment variable to no effect:
"logging__logLevel__Default: "Error"
azure asp.net-core azure-functions
Have you checked logging configuration in host.json or you only want to work with environment variable?
– Jerry Liu
Nov 21 at 3:56
I would like to see if it's possible to control LogLevel using environment variables but I wasn't familiar with the host.json file. When debugging the Function locally using the emulator, I can see that a host.json file is automatically generated but does not contain any logging config. When I edit the file manually I can successfully set the log level. Can I control the generation of this file when developing locally?
– Alasdair Stark
Nov 21 at 4:06
Manual edit is the only way, generation is controlled by Azure function template engine for VS.
– Jerry Liu
Nov 21 at 4:14
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
As per the Azure documentation, Functions V2 uses the .NET Core logging filter hierarchy for configuration.
In the following example, an instance of ILogger is injected into the Run method of the function.
[FunctionName("MyFunction")]
public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger logger, ExecutionContext executionContext)
{
logger.LogInformation("I don't want to see this in production!"));
}
When inspecting the ILogger object, each LoggerInformation element has MinLevel of null which seems to log all levels.
In production, I only want to log at the Error level. I would like to be able to configure this using an environment variable but I cannot find any documentation which explains how to achieve this. I have tried adding the following environment variable to no effect:
"logging__logLevel__Default: "Error"
azure asp.net-core azure-functions
As per the Azure documentation, Functions V2 uses the .NET Core logging filter hierarchy for configuration.
In the following example, an instance of ILogger is injected into the Run method of the function.
[FunctionName("MyFunction")]
public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger logger, ExecutionContext executionContext)
{
logger.LogInformation("I don't want to see this in production!"));
}
When inspecting the ILogger object, each LoggerInformation element has MinLevel of null which seems to log all levels.
In production, I only want to log at the Error level. I would like to be able to configure this using an environment variable but I cannot find any documentation which explains how to achieve this. I have tried adding the following environment variable to no effect:
"logging__logLevel__Default: "Error"
azure asp.net-core azure-functions
azure asp.net-core azure-functions
edited Nov 21 at 7:31
Jerry Liu
7,2131427
7,2131427
asked Nov 21 at 3:51
Alasdair Stark
513421
513421
Have you checked logging configuration in host.json or you only want to work with environment variable?
– Jerry Liu
Nov 21 at 3:56
I would like to see if it's possible to control LogLevel using environment variables but I wasn't familiar with the host.json file. When debugging the Function locally using the emulator, I can see that a host.json file is automatically generated but does not contain any logging config. When I edit the file manually I can successfully set the log level. Can I control the generation of this file when developing locally?
– Alasdair Stark
Nov 21 at 4:06
Manual edit is the only way, generation is controlled by Azure function template engine for VS.
– Jerry Liu
Nov 21 at 4:14
add a comment |
Have you checked logging configuration in host.json or you only want to work with environment variable?
– Jerry Liu
Nov 21 at 3:56
I would like to see if it's possible to control LogLevel using environment variables but I wasn't familiar with the host.json file. When debugging the Function locally using the emulator, I can see that a host.json file is automatically generated but does not contain any logging config. When I edit the file manually I can successfully set the log level. Can I control the generation of this file when developing locally?
– Alasdair Stark
Nov 21 at 4:06
Manual edit is the only way, generation is controlled by Azure function template engine for VS.
– Jerry Liu
Nov 21 at 4:14
Have you checked logging configuration in host.json or you only want to work with environment variable?
– Jerry Liu
Nov 21 at 3:56
Have you checked logging configuration in host.json or you only want to work with environment variable?
– Jerry Liu
Nov 21 at 3:56
I would like to see if it's possible to control LogLevel using environment variables but I wasn't familiar with the host.json file. When debugging the Function locally using the emulator, I can see that a host.json file is automatically generated but does not contain any logging config. When I edit the file manually I can successfully set the log level. Can I control the generation of this file when developing locally?
– Alasdair Stark
Nov 21 at 4:06
I would like to see if it's possible to control LogLevel using environment variables but I wasn't familiar with the host.json file. When debugging the Function locally using the emulator, I can see that a host.json file is automatically generated but does not contain any logging config. When I edit the file manually I can successfully set the log level. Can I control the generation of this file when developing locally?
– Alasdair Stark
Nov 21 at 4:06
Manual edit is the only way, generation is controlled by Azure function template engine for VS.
– Jerry Liu
Nov 21 at 4:14
Manual edit is the only way, generation is controlled by Azure function template engine for VS.
– Jerry Liu
Nov 21 at 4:14
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
I am afraid we can't configure the log level using environment variables. When function host starts, it reads log level from host.json
and inject ILogger instance with corresponding filter rules. Host configurations are not env variables, but we can modify host.json
to change log level.
v2 log configuration in host.json.
"logging": {
"logLevel": {
// For specific function
"Function.MyFunction1": "Information",
// For all functions
"Function":"Error",
// Default settings, e.g. for host
"default": "None"
}
}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
I am afraid we can't configure the log level using environment variables. When function host starts, it reads log level from host.json
and inject ILogger instance with corresponding filter rules. Host configurations are not env variables, but we can modify host.json
to change log level.
v2 log configuration in host.json.
"logging": {
"logLevel": {
// For specific function
"Function.MyFunction1": "Information",
// For all functions
"Function":"Error",
// Default settings, e.g. for host
"default": "None"
}
}
add a comment |
up vote
0
down vote
accepted
I am afraid we can't configure the log level using environment variables. When function host starts, it reads log level from host.json
and inject ILogger instance with corresponding filter rules. Host configurations are not env variables, but we can modify host.json
to change log level.
v2 log configuration in host.json.
"logging": {
"logLevel": {
// For specific function
"Function.MyFunction1": "Information",
// For all functions
"Function":"Error",
// Default settings, e.g. for host
"default": "None"
}
}
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
I am afraid we can't configure the log level using environment variables. When function host starts, it reads log level from host.json
and inject ILogger instance with corresponding filter rules. Host configurations are not env variables, but we can modify host.json
to change log level.
v2 log configuration in host.json.
"logging": {
"logLevel": {
// For specific function
"Function.MyFunction1": "Information",
// For all functions
"Function":"Error",
// Default settings, e.g. for host
"default": "None"
}
}
I am afraid we can't configure the log level using environment variables. When function host starts, it reads log level from host.json
and inject ILogger instance with corresponding filter rules. Host configurations are not env variables, but we can modify host.json
to change log level.
v2 log configuration in host.json.
"logging": {
"logLevel": {
// For specific function
"Function.MyFunction1": "Information",
// For all functions
"Function":"Error",
// Default settings, e.g. for host
"default": "None"
}
}
answered Nov 21 at 7:31
Jerry Liu
7,2131427
7,2131427
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405020%2fconfigure-loglevel-of-azure-function-using-environment-variables%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you checked logging configuration in host.json or you only want to work with environment variable?
– Jerry Liu
Nov 21 at 3:56
I would like to see if it's possible to control LogLevel using environment variables but I wasn't familiar with the host.json file. When debugging the Function locally using the emulator, I can see that a host.json file is automatically generated but does not contain any logging config. When I edit the file manually I can successfully set the log level. Can I control the generation of this file when developing locally?
– Alasdair Stark
Nov 21 at 4:06
Manual edit is the only way, generation is controlled by Azure function template engine for VS.
– Jerry Liu
Nov 21 at 4:14