{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-guides/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"Logging Tutorial","description":"Accelerate E&P application development and protect your innovation by consuming our Data and Domain APIs / Platform APIs.","lang":"en-US","meta":[{"name":"robots","content":"noindex"}],"llmstxt":{"hide":true,"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"logging-tutorial","__idx":0},"children":["Logging Tutorial"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["By the end of the logging tutorial you should feel comfortable logging messages and understand logging level using the IIoT Edge App SDK.  There is nothing extremely special about the logging capability of the SDK compared to open source loggers, but it (like all others) has its own configuration settings which is integrally tied to the SDK's configuration capabilities."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Logging is required by the SDK to allow the SDK the ability to log information about itself."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Before you begin"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You should have completed the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/solutions/agora/quickstartguide"},"children":["Getting Started"]}," section to integrate the AgoraIoT.Edge.App.SDK into your project before starting and have a project ready to use with the tutorial."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"logging-with-string-extensions","__idx":1},"children":["Logging with String Extensions"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["In general, most logging can be accomplished just using String Extensions for Logging, which is what this tutorial focuses on."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["From the IDE, open ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Program.cs"]}," within the Console application created in the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/solutions/agora/quickstartguide"},"children":["Getting Started"]}," tutorial and copy the code below into it:"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"_","__idx":2},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#tab/net"},"children":["NET"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"public class Program\n{\n    public static void Main(string[] args)\n    {\n        \"Starting\".LogHeading();\n        \"Hello from Module!\".LogWarn();\n        $\"The current local time is {DateTime.Now}.\".LogInfo();\n        \"A debug message\".LogDebug();\n        \"A trace message\".LogTrace();\n        \"Stopping\".LogHeading();\n    }\n}\n","lang":"csharp"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"_-1","__idx":3},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#tab/python"},"children":["Python"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"from agoraiot import logger\nimport time\nlogger.heading(\"Starting\")\nlogger.warn(\"Hello from Module!\")\nlogger.info(f\"The current local time is {time.now()}.\")\nlogger.debug(\"A debug message\")\nlogger.trace(\"A trace message\")\nlogger.heading(\"Stopping\")\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Run the application.  You should see the output similar to what is below in the application's Console window."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"plaintext","header":{"controls":{"copy":{}}},"source":"-------------------------------------------------------------------------------\n(33)                                                                   Starting\n-------------------------------------------------------------------------------\nW(36) - Hello from Module!\nI(36) - The current local time is 5/3/2022 5:17:13 PM.\n-------------------------------------------------------------------------------\n(37)                                                                   Stopping\n-------------------------------------------------------------------------------\n","lang":"plaintext"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Within the log, each message begins with the first letter of the LogLevel followed by the number of milliseconds since the application started in parentheses.  If the LogLevel of the message being written is LogLevel.Info, the message will not contain the file, line number, and member name."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Notice that the Debug and Trace messages did not appear. This is because the Logging Level defaults to LogLevel.Info and above. To adjust the level of logging messages output by the Logger for troubleshooting and development use the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["AEA2:LogLevel"]}," configuration setting.  Assigning LogLevel sets the minimum level to be output, which corresponds to the LogLevel enumeration."]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Trace (0): Finest level of logging"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Debug (1): Used for debugging - specifically log values that should not go to Release"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Info (2): General logging information - filename, line number,  and method are not included"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Warn (3): Used to indicate something is not happening as expected"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Error (4): Indicates an error occurred, but not fatally.  Errors are used to indicate that the configuration error or unexpected software problem.  It should not be used to log problems with the workflow or process that the application is performing."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Fatal (5): Generally used just before the application is giving up, just before it stops."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Off (6): Turns off all logging."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Additionally, the level of logging can be adjusted using configuration and by setting the level directly on the logger."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"configuration-settings-affecting-logging-using-aeajson-configuration-file","__idx":4},"children":["Configuration Settings affecting Logging using 'AEA.json' configuration file."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"{\n    ...\n    \"AEA2\": {\n        \"LogLevel\": \"Debug\"\n    }\n    ...\n}\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Programmatically, the default logging level can be overridden calling the appropriate method on the logger."]},{"$$mdtype":"Tag","name":"blockquote","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["[!IMPORTANT]"," ","Setting LogLevel programmatically via the logger API can have unexpected results because Configuration changes will cause the LogLevel to be reset.  To override any configuration setting, use configuration overrides."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"setting-log-level-using-the-logger","__idx":5},"children":["Setting log level using the logger"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"_-2","__idx":6},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#tab/net"},"children":["NET"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"using static Agora.SDK;\n\nLog.SetLevel(Agora.Logging.LogLevel.Debug);\n","lang":"csharp"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"_-3","__idx":7},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#tab/python"},"children":["Python"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"from agoraiot import logger, LogLevel\n\nlogger.set_level(LogLevel.DEBUG)\n\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"setting-log-level-using-configuration-overrides","__idx":8},"children":["Setting log level using configuration overrides"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"_-4","__idx":9},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#tab/net"},"children":["NET"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"using static Agora.SDK;\n\nConfig.Overrides[\"AEA2:LogLevel\"] = \"Debug\";\nConfig.Build();\n","lang":"csharp"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"_-5","__idx":10},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#tab/python"},"children":["Python"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"from agoraiot import config\n\nconfig.overrides[\"AEA2:LogLevel\"] = \"Debug\"\nconfig.build();\n","lang":"python"},"children":[]}]},"headings":[{"value":"Logging Tutorial","id":"logging-tutorial","depth":2},{"value":"Logging with String Extensions","id":"logging-with-string-extensions","depth":3},{"value":"","id":"_","depth":1},{"value":"","id":"_-1","depth":1},{"value":"Configuration Settings affecting Logging using 'AEA.json' configuration file.","id":"configuration-settings-affecting-logging-using-aeajson-configuration-file","depth":3},{"value":"Setting log level using the logger","id":"setting-log-level-using-the-logger","depth":4},{"value":"","id":"_-2","depth":1},{"value":"","id":"_-3","depth":1},{"value":"Setting log level using configuration overrides","id":"setting-log-level-using-configuration-overrides","depth":4},{"value":"","id":"_-4","depth":1},{"value":"","id":"_-5","depth":1}],"frontmatter":{"seo":{"title":"Logging Tutorial"}},"lastModified":"2026-01-14T00:18:30.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/solutions/agora/tutorial/loggingtutorial","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}