Skip to content

Commit ef910f2

Browse files
authored
Merge pull request #54112 from rodrigoaatmicrosoft/patch-4
Adding Log documentation to C# UDF
2 parents a2643b6 + 3e3fade commit ef910f2

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 allows you to capture custom information while a job is running. You can use log data to debug or assess the correctness of the custom code in real time.
141+
142+
The `StreamingContext` class lets you publish diagnostic 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 UDF method and can be used within the UDF to publish custom log information. In the example below, `MyUdfMethod` defines a **data** input, which is 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+
The `StreamingContext` value doesn't need to be passed in by the SQL query. Azure Stream Analytics provides a context object automatically if an input parameter is present. The use of the `MyUdfMethod` does not change, as shown in the following query:
169+
170+
```sql
171+
SELECT udf.MyUdfMethod(input.value) as udfValue FROM input
172+
```
173+
174+
You can access log messages 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)