diff --git a/BililiveRecorder.Core/Recording/RawDataRecordTask.cs b/BililiveRecorder.Core/Recording/RawDataRecordTask.cs index cc4b05b..ee184c6 100644 --- a/BililiveRecorder.Core/Recording/RawDataRecordTask.cs +++ b/BililiveRecorder.Core/Recording/RawDataRecordTask.cs @@ -40,6 +40,8 @@ namespace BililiveRecorder.Core.Recording }; this.OnRecordFileOpening(this.fileOpeningEventArgs); + this.logger.Information("新建录制文件 {Path}", fullPath); + var file = new FileStream(fullPath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read | FileShare.Delete); _ = Task.Run(async () => await this.WriteStreamToFileAsync(stream, file).ConfigureAwait(false)); diff --git a/BililiveRecorder.Core/Recording/RecordTaskFactory.cs b/BililiveRecorder.Core/Recording/RecordTaskFactory.cs index 469f938..7fa467c 100644 --- a/BililiveRecorder.Core/Recording/RecordTaskFactory.cs +++ b/BililiveRecorder.Core/Recording/RecordTaskFactory.cs @@ -1,23 +1,35 @@ using System; using BililiveRecorder.Core.Config.V2; using Microsoft.Extensions.DependencyInjection; +using Serilog; namespace BililiveRecorder.Core.Recording { public class RecordTaskFactory : IRecordTaskFactory { + private readonly ILogger logger; private readonly IServiceProvider serviceProvider; + private readonly ObjectFactory factoryRawData; + private readonly ObjectFactory factoryStandard; - public RecordTaskFactory(IServiceProvider serviceProvider) + public RecordTaskFactory(ILogger logger, IServiceProvider serviceProvider) { + this.logger = logger?.ForContext() ?? throw new ArgumentNullException(nameof(logger)); this.serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); + + this.factoryRawData = ActivatorUtilities.CreateFactory(typeof(RawDataRecordTask), new[] { typeof(IRoom) }); + this.factoryStandard = ActivatorUtilities.CreateFactory(typeof(StandardRecordTask), new[] { typeof(IRoom) }); } - public IRecordTask CreateRecordTask(IRoom room) => - room.RoomConfig.RecordMode switch + public IRecordTask CreateRecordTask(IRoom room) + { + var recordMode = room.RoomConfig.RecordMode; + this.logger.Debug("Create record task with mode {RecordMode} for room {RoomId}", recordMode, room.RoomConfig.RoomId); + return recordMode switch { - RecordMode.RawData => ActivatorUtilities.CreateInstance(this.serviceProvider, room), - _ => ActivatorUtilities.CreateInstance(this.serviceProvider, room) + RecordMode.RawData => (IRecordTask)this.factoryRawData(this.serviceProvider, new[] { room }), + _ => (IRecordTask)this.factoryStandard(this.serviceProvider, new[] { room }) }; + } } }