diff --git a/src/Ray.BiliBiliTool.Console/appsettings.json b/src/Ray.BiliBiliTool.Console/appsettings.json
index 48061223e..90adac573 100644
--- a/src/Ray.BiliBiliTool.Console/appsettings.json
+++ b/src/Ray.BiliBiliTool.Console/appsettings.json
@@ -113,7 +113,8 @@
"botToken": "",
"chatId": "",
"restrictedToMinimumLevel": "Information",
- "proxy": "" //代理,user:password@host:port
+ "proxy": "", //代理,user:password@host:port
+ "apiHost": ""
}
},
//4.企业微信机器人(https://work.weixin.qq.com/api/doc/90000/90136/91770)
diff --git a/src/Ray.Serilog.Sinks/Ray.Serilog.Sinks.TelegramBatched/TelegramApiClient.cs b/src/Ray.Serilog.Sinks/Ray.Serilog.Sinks.TelegramBatched/TelegramApiClient.cs
index 3004c40ef..735475dc6 100644
--- a/src/Ray.Serilog.Sinks/Ray.Serilog.Sinks.TelegramBatched/TelegramApiClient.cs
+++ b/src/Ray.Serilog.Sinks/Ray.Serilog.Sinks.TelegramBatched/TelegramApiClient.cs
@@ -32,7 +32,7 @@ public class TelegramApiClient : PushService
/// The Telegram bot token.
/// The timeout seconds.
/// Thrown if the bot token is null or empty.
- public TelegramApiClient(string botToken, string chatId, string proxy="", int timeoutSeconds = 10)
+ public TelegramApiClient(string botToken, string chatId, string proxy = "", string apiHost = "", int timeoutSeconds = 10)
{
if (string.IsNullOrWhiteSpace(botToken))
{
@@ -42,8 +42,12 @@ public TelegramApiClient(string botToken, string chatId, string proxy="", int ti
_chatId = chatId;
_proxy = proxy;
-
- this._apiUrl = new Uri($"{TelegramBotApiUrl}{botToken}/sendMessage");
+ var botApiUrl = TelegramBotApiUrl;
+ if (!string.IsNullOrWhiteSpace(apiHost))
+ {
+ botApiUrl = apiHost;
+ }
+ this._apiUrl = new Uri($"{botApiUrl}{botToken}/sendMessage");
if (proxy.IsNotNullOrEmpty())
{
@@ -101,7 +105,7 @@ private WebProxy GetWebProxy(string proxyAddress)
var credentials = new NetworkCredential(proxyUser, proxyPass);
- webProxy = new WebProxy(address, true,null, credentials);
+ webProxy = new WebProxy(address, true, null, credentials);
}
else
{
diff --git a/src/Ray.Serilog.Sinks/Ray.Serilog.Sinks.TelegramBatched/TelegramBatchedSink.cs b/src/Ray.Serilog.Sinks/Ray.Serilog.Sinks.TelegramBatched/TelegramBatchedSink.cs
index 5ac1455aa..4fa7d2b2e 100644
--- a/src/Ray.Serilog.Sinks/Ray.Serilog.Sinks.TelegramBatched/TelegramBatchedSink.cs
+++ b/src/Ray.Serilog.Sinks/Ray.Serilog.Sinks.TelegramBatched/TelegramBatchedSink.cs
@@ -15,11 +15,13 @@ public class TelegramBatchedSink : BatchedSink
private readonly string _botToken;
private readonly string _chatId;
private readonly string _proxy;
+ private readonly string _apiHost;
public TelegramBatchedSink(
string botToken,
string chatId,
string proxy,
+ string apiHost,
Predicate predicate,
bool sendBatchesAsOneMessages,
IFormatProvider formatProvider,
@@ -29,6 +31,7 @@ LogEventLevel minimumLogEventLevel
_botToken = botToken;
_chatId = chatId;
_proxy = proxy;
+ _apiHost = apiHost;
}
public override void Emit(LogEvent logEvent)
@@ -37,7 +40,7 @@ public override void Emit(LogEvent logEvent)
base.Emit(logEvent);
}
- protected override PushService PushService => new TelegramApiClient(_botToken, _chatId, _proxy, 5);
+ protected override PushService PushService => new TelegramApiClient(_botToken, _chatId, _proxy, _apiHost, 5);
public override void Dispose()
{
diff --git a/src/Ray.Serilog.Sinks/Ray.Serilog.Sinks.TelegramBatched/TelegramLoggerConfigurationExtensions.cs b/src/Ray.Serilog.Sinks/Ray.Serilog.Sinks.TelegramBatched/TelegramLoggerConfigurationExtensions.cs
index ab9ebb466..9b4ca8d51 100644
--- a/src/Ray.Serilog.Sinks/Ray.Serilog.Sinks.TelegramBatched/TelegramLoggerConfigurationExtensions.cs
+++ b/src/Ray.Serilog.Sinks/Ray.Serilog.Sinks.TelegramBatched/TelegramLoggerConfigurationExtensions.cs
@@ -13,6 +13,7 @@ public static LoggerConfiguration TelegramBatched(
string botToken,
string chatId,
string proxy,
+ string apiHost,
string containsTrigger = Constants.DefaultContainsTrigger,
bool sendBatchesAsOneMessages = true,
IFormatProvider formatProvider = null,
@@ -22,7 +23,7 @@ public static LoggerConfiguration TelegramBatched(
if (containsTrigger.IsNullOrEmpty()) containsTrigger = Constants.DefaultContainsTrigger;
Predicate predicate = x => x.MessageTemplate.Text.Contains(containsTrigger);
- return loggerSinkConfiguration.Sink(new TelegramBatchedSink(botToken, chatId, proxy, predicate, sendBatchesAsOneMessages, formatProvider, restrictedToMinimumLevel), restrictedToMinimumLevel);
+ return loggerSinkConfiguration.Sink(new TelegramBatchedSink(botToken, chatId, proxy, apiHost, predicate, sendBatchesAsOneMessages, formatProvider, restrictedToMinimumLevel), restrictedToMinimumLevel);
}
}
}