Skip to content

Commit 3839982

Browse files
Adding Log documentation to C# UDF
Adding a small description on how to enable user logging in C# UDF.
1 parent 43f73b7 commit 3839982

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

articles/stream-analytics/stream-analytics-edge-csharp-udf-methods.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,43 @@ Expand the **User-Defined Code Configuration** section, and fill out the configu
136136
|Custom Code Assembly Source|Existing assembly packages from the cloud|
137137
|Custom Code Assembly Source|UserCustomCode.zip|
138138

139+
## User Logging
140+
The logging mechanism allow users to capture custom information during job run. Log data can be used to debug or assess the correctness of the custom code at real time.
141+
142+
The `StreamingContext` class provides a mechanism for publishing diagnostics information using the `StreamingDiagnostics.WriteError` function. The code below shows the interface exposed by Azure Stream Analytics.
143+
144+
```csharp
145+
public abstract class StreamingContext
146+
{
147+
public abstract StreamingDiagnostics Diagnostics { get; }
148+
}
149+
150+
public abstract class StreamingDiagnostics
151+
{
152+
public abstract void WriteError(string briefMessage, string detailedMessage);
153+
}
154+
```
155+
156+
`StreamingContext` is passed as an input parameter to the user UDF method and can be used within the UDF to publish user custom log information. In the example below `MyUdfMethod` defines a **data** input which the value will be provided by the query and a **context** input as the `StreamingContext` provided by the runtime engine.
157+
158+
```csharp
159+
public static long MyUdfMethod(long data, StreamingContext context)
160+
{
161+
// write log
162+
context.Diagnostics.WriteError("User Log", "This is a log message");
163+
164+
return data;
165+
}
166+
```
167+
168+
`StreamingContext` value does not need to be passed by the user in the SQL query, Azure Stream Analytics will provide a context object automatically if input parameter is present. The use of the `MyUdfMethod` does not change as shown below.
169+
170+
```SQL
171+
SELECT udf.MyUdfMethod(input.value) as udfValue FROM input
172+
```
173+
174+
Log messages can be accessed through the [Diagnostic Logs](data-errors.md).
175+
139176
## Limitations
140177
The UDF preview currently has the following limitations:
141178

0 commit comments

Comments
 (0)