简体   繁体   English

使用 NLog 登录到 Microsoft Teams 中的频道

[英]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.

相关问题 Teams 频道中 Microsoft Bot Framework 中的后台作业 - Background jobs in Microsoft Bot Framework in Teams Channel 阅读 Microsoft Teams 频道消息(Microsoft graph API、C#) - Read Microsoft Teams channel messages (Microsoft graph API, C#) 如何使用 csharp 向 Microsoft Teams 频道发送简单消息? - How to send simple message to Microsoft Teams channel using csharp? 在 C# 中通过 Microsoft Graph API 在 Microsoft 团队通用频道中发布消息时出现禁止访问错误 - Getting Forbidden error while posting the message in Microsoft teams general channel via Microsoft Graph API in C# 在 Microsoft Teams 中提及用户出现“BadRequest”异常,Bot 服务的 Ms 团队频道显示错误“提及实体与文本不匹配” - Mention user in Microsoft Teams get exception of 'BadRequest', Ms teams channel of Bot Service shows error 'Mention entity does not match text' Bot Framework bot无法在未提示的情况下在Microsoft Teams频道中发布 - Bot Framework bot can't post in Microsoft Teams channel without being prompted Microsoft Teams Bot文件卡信息通过向频道发送文件信息而损坏 - Microsoft Teams Bot file card info is corrupted by sending a file info to a channel 使用自定义API机器人无法使用Bot框架在Microsoft Teams频道中发布操作卡 - Using Custom API bot can't post action card in Microsoft Teams channel using Bot framework 如何使用 Microsoft.Extensions.Logging 将 NLog 中的自定义字段记录到数据库? - How do I log a custom field in NLog to database using Microsoft.Extensions.Logging? nlog登录到特定方法 - nlog to log to specific methods
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM