0
所以我有這個樣本使用我公司的DLL之一。C#Visual Studio運行程序沒有調試器(ctrl + F5)
namespace LoggingSample
{
internal static class Log
{
private static ILogger s_log = LoggerRegistry.CreateLogger("ManagedLoggingSample");
static internal ILogger Logger
{
get { return s_log; }
}
}
class Program
{
static void Main(string[] args)
{
ILogProvider logProvider = new Logging.Provider.Log4netProvider("logging.config.xml") as ILogProvider;
LoggerConfig.registerLogInterface(logProvider);
Console.WriteLine("Initializing logging");
Log.Logger.message(SEVERITY.LOG_DEBUG, "Debug message 1");
// Add more logs
Log.Logger.message(SEVERITY.LOG_INFO, "Log info Message {0} {1}", 2, "I am an error logged message");
Log.Logger.debug("Debug Message 2");
Log.Logger.error("Error Log message {0} {1}", 4, "i am an error message");
Console.WriteLine("Done");
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
}
我的問題是,在控制檯上的消息顯示在調試和發佈只運行沒有調試器。
該方案還對輸出文件的文本,但沒有調試器中的文件是空的; 任何人都知道這裏可能是什麼問題?可能是一個設置問題?
.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="RollingLogFileAppender" />
<appender-ref ref="ColoredConsoleAppender" />
</root>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="ManagedLoggingSample.log" />
<appendToFile value="false" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="2KB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
</layout>
</appender>
<appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
<mapping>
<level value="ERROR" />
<foreColor value="White" />
<backColor value="Red, HighIntensity" />
</mapping>
<mapping>
<level value="DEBUG" />
<backColor value="Green" />
</mapping>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<logger name="ManagedLoggingSample" >
<level value="ALL" />
<appender-ref ref="RollingLogFileAppender" />
</logger>
</log4net>
我忘了提及,只有在沒有調試器釋放它不顯示在控制檯和日誌文件上的任何東西是空的,從調試中的.exe工作得很好。
你可以發佈你的logging.config.xml嗎? – jacob
嗨@jacob,我附加了.xml文件 – cosmotel