Objective
Log the errors to Microsoft Teams with NLog from a console program.
Issue
Was able to log to the console, but not to Teams
Code
Config:
<targets>
<target xsi:type="Console" name="console"/>
<target xsi:type="WebService"
name="microsoft-teams"
url="https://outlook.office.com/webhook/abcd"
protocol='JsonPost'
encoding='UTF-8'
includeBOM='false' >
</target>
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="console" />
<logger name='*' writeTo='microsoft-teams' />
</rules>
Logging code:
private static Logger logger = LogManager.GetCurrentClassLogger();
public static void Main(string[] args) {
logger.Error("{'text':'test'}");
logger.Fatal("Sample fatal error message");
}
The console target displayed the errors very well. But the Teams channel didn't have log, the nlog-internal.log
showed
System.Net.WebException: The remote server returned an error: (400) Bad Request. at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
Any insight would be greatly appreciated!