Created
January 28, 2021 07:48
-
-
Save 0x49D1/91a92215762d9f20610875cd413fcfd9 to your computer and use it in GitHub Desktop.
Using NLog WebService target for Telegram example. Send logs to Telegram via https://core.telegram.org/bots/api#sendmessage Telegram Bot API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd" | |
autoReload="true" | |
throwExceptions="false" | |
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log"> | |
<variable name="telegramBotToken" value="YOUR_TELEGRAM_BOT_TOKEN"/> | |
<variable name="telegramChatId" value="YOUR_BOT_CHAT_ID"/> | |
<targets async="true"> | |
<target xsi:type="WebService" | |
name="telegram" | |
url="https://api.telegram.org/bot${telegramBotToken}/sendMessage" | |
encoding="utf-8" protocol="JsonPost"> | |
<parameter name=""> | |
<layout xsi:type="JsonLayout" includeAllProperties="true"> | |
<attribute name="chat_id" layout="${telegramChatId}"/> | |
<attribute name="parse_mode" layout="HTML"/> | |
<attribute name="text" | |
layout="${longdate}|#${level}|<i>${logger}</i>|<pre><code>${message} ${exception:format=@}</code></pre>"/> | |
</layout> | |
</parameter> | |
</target> | |
</targets> | |
<rules> | |
<logger name="*" minlevel="Trace" writeTo="telegram"/> | |
</rules> | |
</nlog> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment