[英]Log to a channel in Microsoft Teams with NLog
Objective目标
Log the errors to Microsoft Teams with NLog from a console program.使用 NLog 从控制台程序将错误记录到 Microsoft Teams。
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但是 Teams 频道没有日志, nlog-internal.log
显示
System.Net.WebException: The remote server returned an error: (400) Bad Request. System.Net.WebException:远程服务器返回错误:(400) 错误请求。 at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)在 System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
Any insight would be greatly appreciated!任何见解将不胜感激!
You need at least send some parameters, see example webserver target:您至少需要发送一些参数,请参阅示例网络服务器目标:
<target type='WebService'
name='ws'
url='http://localhost:1234/logme'
protocol='HttpPost'
encoding='UTF-8' >
<parameter name='param1' type='System.String' layout='${message}'/>
<parameter name='param2' type='System.String' layout='${level}'/>
</target>
If this still isn't working, I would recommend checking the call with Fiddler如果这仍然不起作用,我建议使用Fiddler检查通话
I know it is a little bit late, but you can try the NLog extension I created.我知道现在有点晚了,但是您可以尝试我创建的 NLog 扩展。 https://github.com/jedipi/NLog.Targets.MicrosoftTeams https://github.com/jedipi/NLog.Targets.MicrosoftTeams
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.