public void PartialTrustSuccess(int times, string fileWritePath)
        {
            var filePath = Path.Combine(fileWritePath, "${level}.txt");


            var configXml = string.Format(@"
            <nlog throwExceptions='false'>
                <targets async='true'> 
                    <target name='file' type='file' layout='${{message}} ${{threadid}}' filename='{0}' LineEnding='lf' />
                </targets>
                <rules>
                    <logger name='*' minlevel='Debug' appendto='file'>
                    </logger>
                </rules>
            </nlog>", filePath);

            LogManager.Configuration = NLogTestBase.CreateConfigurationFromString(configXml);

            //this method gave issues
            LogFactory.LogConfigurationInitialized();

            ILogger logger = LogManager.GetLogger("NLog.UnitTests.Targets.FileTargetTests");

            for (var i = 0; i < times; ++i)
            {
                logger.Trace("@@@");
                logger.Debug("aaa");
                logger.Info("bbb");
                logger.Warn("ccc");
                logger.Error("ddd");
                logger.Fatal("eee");
            }

            LogManager.Flush();
        }
예제 #2
0
        public void PartialTrustSuccess(int times, string fileWritePath)
        {
            var filePath = Path.Combine(fileWritePath, "${level}.txt");

            // NOTE Using BufferingWrapper to validate that DomainUnload remembers to perform flush
            var configXml = $@"
            <nlog throwExceptions='false'>
                <targets async='true'> 
                    <target name='file' type='BufferingWrapper' bufferSize='10000' flushTimeout='15000'>
                        <target name='filewrapped' type='file' layout='${{message}} ${{threadid}}' filename='{
                    filePath
                }' LineEnding='lf' />
                    </target>
                </targets>
                <rules>
                    <logger name='*' minlevel='Debug' appendto='file'>
                    </logger>
                </rules>
            </nlog>";

            LogManager.Configuration = NLogTestBase.CreateConfigurationFromString(configXml);

            //this method gave issues
            LogFactory.LogConfigurationInitialized();

            ILogger logger = LogManager.GetLogger("NLog.UnitTests.Targets.FileTargetTests");

            for (var i = 0; i < times; ++i)
            {
                logger.Trace("@@@");
                logger.Debug("aaa");
                logger.Info("bbb");
                logger.Warn("ccc");
                logger.Error("ddd");
                logger.Fatal("eee");
            }
        }