与备份附加器记录备份

2023-09-05 01:10:05 作者:在最美的时光遇见谁

有任何.NET日志框架有切换的appender,如果事情是错的当前能力。其实我要的是以下内容:

Is there any .NET logging framework that have ability to switch appender if something is wrong with current one. Actually what I want is following:

如果我使用数据库附加器和出问题的时候用的数据库(如服务器出现故障,失去动力...)我想切换到第二个附加目的地(例如其登录文件)。

If I'm using database appender and when something goes wrong with database (e.g. server goes down, lose power...) I want to switch to second appender (e.g. which log into file).

这是否有能力执行下列操作之一:log4net的,NLOG,企业库?我一直在寻找这一点,但没有运气。

Does this ability have one of following: log4net, NLog, Enterprise Library? I was looking for this but no luck.

推荐答案

由于log4netContribute FallbackAppender不能按预期工作我做了深入的研究,发现这种能力具有n日志。我测试了它,它正在像一个魅力;)下面是一个例子:

Because log4netContribute FallbackAppender is not working as expected I've made deep research and found that this ability has nLog. I tested it and it is working like a charm ;) Here is an example:

[app.config中]

[app.config]

<?xml version="1.0"?>
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<variable name="appTitle" value="My Application"/>
<targets>
<target name="file" xsi:type="FallbackGroup" returnToFirstOnSuccess="true">
<target xsi:type="File" fileName="x:\vladimir.txt" />
<target xsi:type="File" fileName="w:\pavlovic.txt" />
<target xsi:type="File" fileName="w:\zvjerka24.txt" />
</target>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
</rules>
</nlog>
</configuration>

[code]

[code]

Logger _logger = LogManager.GetCurrentClassLogger();
_logger.Info("Neki Info");
_logger.Debug("Neki debug");
_logger.Error("Neki  ERROR");
_logger.Error("Pa jos neki");