调整了一些日志输出

This commit is contained in:
Genteure 2018-11-10 12:17:41 +08:00
parent f3251d7e05
commit e7c6fd0a9b
4 changed files with 36 additions and 15 deletions

View File

@ -41,6 +41,8 @@ namespace BililiveRecorder.Core
}
private bool _isConnected = false;
private int RoomId;
public DanmakuReceiver(Func<TcpClient> funcTcpClient)
{
this.funcTcpClient = funcTcpClient;
@ -62,11 +64,11 @@ namespace BililiveRecorder.Core
throw new InvalidOperationException();
}
int channelId = roomId;
RoomId = roomId;
try
{
var request2 = WebRequest.Create(CIDInfoUrl + channelId);
var request2 = WebRequest.Create(CIDInfoUrl + RoomId);
request2.Timeout = 2000;
var response2 = request2.GetResponse();
using (var stream = response2.GetResponseStream())
@ -87,32 +89,32 @@ namespace BililiveRecorder.Core
HttpWebResponse errorResponse = ex.Response as HttpWebResponse;
if (errorResponse?.StatusCode == HttpStatusCode.NotFound)
{ // 直播间不存在HTTP 404
logger.Log(roomId, LogLevel.Warn, "该直播间疑似不存在", ex);
logger.Log(RoomId, LogLevel.Warn, "该直播间疑似不存在", ex);
}
else
{ // B站服务器响应错误
logger.Log(roomId, LogLevel.Warn, "B站服务器响应弹幕服务器地址出错", ex);
logger.Log(RoomId, LogLevel.Warn, "B站服务器响应弹幕服务器地址出错", ex);
}
}
catch (Exception ex)
{ // 其他错误XML解析错误
logger.Log(roomId, LogLevel.Warn, "获取弹幕服务器地址时出现未知错误", ex);
logger.Log(RoomId, LogLevel.Warn, "获取弹幕服务器地址时出现未知错误", ex);
}
Client = funcTcpClient();
Client.Connect(ChatHost, ChatPort);
if (!Client.Connected)
{
return false;
}
NetStream = Client.GetStream();
SendSocketData(7, "{\"roomid\":" + channelId + ",\"uid\":0}");
SendSocketData(7, "{\"roomid\":" + RoomId + ",\"uid\":0}");
IsConnected = true;
ReceiveMessageLoopThread = new Thread(ReceiveMessageLoop)
{
Name = "ReceiveMessageLoop " + channelId,
Name = "ReceiveMessageLoop " + RoomId,
IsBackground = true
};
ReceiveMessageLoopThread.Start();
@ -129,7 +131,7 @@ namespace BililiveRecorder.Core
catch (Exception ex)
{
Error = ex;
logger.Log(roomId, LogLevel.Error, "连接弹幕服务器时发生了未知错误", ex);
logger.Log(RoomId, LogLevel.Error, "连接弹幕服务器时发生了未知错误", ex);
return false;
}
}
@ -149,7 +151,7 @@ namespace BililiveRecorder.Core
private void ReceiveMessageLoop()
{
logger.Trace("ReceiveMessageLoop Started!");
logger.Trace("ReceiveMessageLoop Started! " + RoomId);
try
{
var stableBuffer = new byte[Client.ReceiveBufferSize];
@ -236,7 +238,7 @@ namespace BililiveRecorder.Core
{
if (IsConnected)
{
logger.Debug("Disconnected");
logger.Debug("Disconnected " + RoomId);
IsConnected = false;
Client.Close();
NetStream = null;
@ -254,7 +256,7 @@ namespace BililiveRecorder.Core
private void SendHeartbeat()
{
SendSocketData(2);
logger.Trace("Message Sent: Heartbeat");
// logger.Trace("Message Sent: Heartbeat");
}
private void SendSocketData(int action, string body = "")

View File

@ -180,7 +180,7 @@ namespace BililiveRecorder.Core
{
string flv_path = BililiveAPI.GetPlayUrl(RealRoomid);
logger.Log(RealRoomid, LogLevel.Debug, "直播流地址: " + flv_path);
request = WebRequest.CreateHttp(flv_path);
request.Accept = "*/*";
request.AllowAutoRedirect = true;

View File

@ -28,10 +28,18 @@ namespace BililiveRecorder.Core
tokenSource = new CancellationTokenSource();
Repeat.Interval(TimeSpan.FromSeconds(6), DownloadWatchdog, tokenSource.Token);
Rooms.CollectionChanged += (sender, e) =>
{
logger.Debug($"Rooms.CollectionChanged;{e.Action};" +
$"O:{e.OldItems.Cast<IRecordedRoom>().Select(rr => rr.RealRoomid.ToString()).Aggregate((current, next) => current + "," + next)};" +
$"N:{e.NewItems.Cast<IRecordedRoom>().Select(rr => rr.RealRoomid.ToString()).Aggregate((current, next) => current + "," + next)}");
};
}
public bool Initialize(string workdir)
{
logger.Debug("Initialize: " + workdir);
if (ConfigParser.Load(directory: workdir, config: Config))
{
_valid = true;
@ -54,7 +62,15 @@ namespace BililiveRecorder.Core
/// </summary>
/// <param name="roomid">房间号(支持短号)</param>
/// <exception cref="ArgumentOutOfRangeException"/>
public void AddRoom(int roomid, bool enabled = false)
public void AddRoom(int roomid) => AddRoom(roomid, false);
/// <summary>
/// 添加直播间到录播姬
/// </summary>
/// <param name="roomid">房间号(支持短号)</param>
/// <param name="enabled">是否默认启用</param>
/// <exception cref="ArgumentOutOfRangeException"/>
public void AddRoom(int roomid, bool enabled)
{
if (!_valid) { throw new InvalidOperationException("Not Initialized"); }
if (roomid <= 0)
@ -69,6 +85,7 @@ namespace BililiveRecorder.Core
}
Rooms.Add(rr);
logger.Debug("AddRoom 添加了直播间 " + rr.RealRoomid);
}
/// <summary>
@ -80,11 +97,13 @@ namespace BililiveRecorder.Core
if (!_valid) { throw new InvalidOperationException("Not Initialized"); }
rr.Shutdown();
Rooms.Remove(rr);
logger.Debug("RemoveRoom 移除了直播间 " + rr.RealRoomid);
}
public void Shutdown()
{
if (!_valid) { throw new InvalidOperationException("Not Initialized"); }
logger.Debug("Shutdown called.");
tokenSource.Cancel();
Config.RoomList = new List<RoomV1>();

View File

@ -26,7 +26,7 @@ namespace BililiveRecorder.Core
private void Receiver_ReceivedRoomCount(object sender, ReceivedRoomCountArgs e)
{
logger.Log(Roomid, LogLevel.Trace, "直播间人气: " + e.UserCount.ToString());
// logger.Log(Roomid, LogLevel.Trace, "直播间人气: " + e.UserCount.ToString());
}
private void Receiver_ReceivedDanmaku(object sender, ReceivedDanmakuArgs e)