-
Notifications
You must be signed in to change notification settings - Fork 442
ILogger
Functions has support for logging through the Microsoft.Extensions.Logging.ILogger interface. At a high level, this is not much different than logging via the TraceWriter
: logs continue to go to the file system and will also go to Application Insights (currently in Preview) if the APPINSIGHTS_INSTRUMENTATIONKEY
app setting is set. The main advantage of using ILogger is that you get support for structured logging via Application Insights, which allows for richer Analytics support.
To use ILogger
as your logging interface, simply add a parameter to your function signature and use any of the logger extensions:
public static void Run(string myQueueItem, ILogger logger)
{
logger.LogInformation("C# Queue trigger function processed: {message}", myQueueItem);
}
The ILogger
extensions allow you pass strings with placeholders that are made available to any registered ILoggerProvider
. This allows a provider to write more detailed, queryable log data (rather than just a simple string). If you look at the example above, the line logger.LogInformation("C# Queue trigger function processed: {myQueueItem}", myQueueItem)
is not passing a formatted string; rather it is passing a string and an object. Behind-the-scenes, the logger formats the string for you but also provides a dictionary that contains a key message
with the value from the myQueueItem
parameter.
What this means for Functions is that the log message will be passed to Application Insights as a Trace message, with the placeholder dictionary added to the customDimensions
field. The keys will be begin with prop__
to prevent any collisions with values that the Functions host may add directly to customDimensions
. You can then query for these placeholders in Application Insights Analytics.
Note: Application Insights support is still in Preview, so the exact shape of this data in Application Insights is still being discussed and may change before Application Insights support hits GA.
{
customDimensions: {
"prop__{OriginalFormat}":"C# Queue trigger function processed: {message}",
"Category":"Function",
"prop__message":"c9519cbf-b1e6-4b9b-bf24-cb7d10b1bb89"
}
// snipping other values
}
- Configuration Settings
- function.json
- host.json
- host.json (v2)
- Http Functions
- Function Runtime Versioning
- Official Functions developers guide
- Host Health Monitor
- Managing Connections
- Renaming a Function
- Retrieving information about the currently running function
- Site Extension Resolution
- Linux Consumption Regions
- Using LinuxFxVersion for Linux Function apps
- Out-of-proc Cancellation Tokens
- Assembly Resolution in Azure Functions
- ILogger
- Precompiled functions
- Official Functions C# developer reference
- Contributor Onboarding
- Development Process
- Deploying the Functions runtime as a private site extension
- Authoring & Testing Language Extensions
- Bindings in out-of-proc
- Language Extensibility
- Worker Capabilities
- Investigating and reporting issues with timer triggered functions not firing
- Sharing Your Function App name privately
- Azure Functions CLI release notes [moved here]
- Function App Zipped Deployment [deprecated]