Ejemplo n.º 1
0
        public virtual void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper)
        {
            try
            {
                TestOutputHelper = testOutputHelper;

                var classType         = GetType();
                var logLevelAttribute = methodInfo.GetCustomAttribute <LogLevelAttribute>()
                                        ?? methodInfo.DeclaringType.GetCustomAttribute <LogLevelAttribute>()
                                        ?? methodInfo.DeclaringType.Assembly.GetCustomAttribute <LogLevelAttribute>();

                // internal for testing
                ResolvedTestClassName = context.FileOutput.TestClassName;

                _testLog = AssemblyTestLog
                           .ForAssembly(classType.GetTypeInfo().Assembly)
                           .StartTestLog(
                    TestOutputHelper,
                    context.FileOutput.TestClassName,
                    out var loggerFactory,
                    logLevelAttribute?.LogLevel ?? LogLevel.Debug,
                    out var resolvedTestName,
                    out var logDirectory,
                    context.FileOutput.TestName);

                ResolvedLogOutputDirectory = logDirectory;
                ResolvedTestMethodName     = resolvedTestName;

                LoggerFactory = loggerFactory;
                Logger        = loggerFactory.CreateLogger(classType);
            }
            catch (Exception e)
            {
                _initializationException = ExceptionDispatchInfo.Capture(e);
            }
        }
Ejemplo n.º 2
0
 public IDisposable StartLog(out ILoggerFactory loggerFactory, LogLevel minLogLevel, [CallerMemberName] string testName = null)
 {
     return(AssemblyTestLog.ForAssembly(GetType().GetTypeInfo().Assembly).StartTestLog(TestOutputHelper, GetType().FullName, out loggerFactory, minLogLevel, testName));
 }