我使用NLOG一個具體的目標有兩個目標:僅記錄在運行時
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets async="true">
<target name="logfile" xsi:type="File" fileName="my.log"/>
<target name="console" xsi:type="Console"/>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="logfile"/>
<logger name="*" minlevel="Info" writeTo="console"/>
</rules>
</nlog>
是否有可能登陸的消息只對「日誌文」的目標,而不必寫入「控制檯消息「目標呢?
EDIT
澄清:我想直接在運行時從相同的類,以不同記錄器的消息(W/O不必改變XML)。類似於:
class Program
{
static Logger _logger = LogManager.GetCurrentClassLogger();
static void Main(string[] args)
{
// Note - _logger.InfoToTarget() does not really exist
_logger.InfoToTarget("logfile", "This is my very detailed message, possibly with object dumps");
_logger.InfoToTarget("console", "Short message");
}
}
我知道這會將我的代碼與NLlog.config文件結合在一起。
這不回答問題... – ilans