English 中文(简体)
与备份投稿的对账
原标题:Logging with backup appender

是的。 NET的伐木框架,如果与目前的情况不符,则有能力转换器。 实际上,我希望的是:

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、企业图书馆。 我期待着这一点,但没有uck。

最佳回答

日元 五. 补偿 申请人没有按照预期的I ve进行深层研究,发现这种能力是行不通的。 我测试了它,它正像一家药店那样工作。 例如:

[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>

[编码]

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

For completeness: Enterprise Library supports a configurable Error Special Source where you can set an "appender" to log messages that have errored. Once configured this just works without any programming.

唯一的倒数是,它将实际将所出现的例外情况与具体格式的伐木细节加以记录,这种格式无法改变,因此无法灵活。 如果你想提取错误的标识信息并将其输入原始伐木目的地(尽管这种格式是众所周知的,因此有可能加以分类),那是好的。

就我所知,M.4net目前并不支持备份发送人而言,在记录4net的积压专题中存在着(或是否)公开的问题。 但我认为,名为

记录仪允许你通过一个配置文件达到多个目标。 Don tabes to set起来ignoreFailures,以确保任何装置/单位故障都被忽视:

<?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>
        <target name="logfile" xsi:type="File" />
        <target name="db" xsi:type="Database" />
    </targets>

    <rules>
        <logger name="*" levels="Info" writeTo="logfile,db" />
    </rules>
</nlog> 

See database Target in Nlog documentation for more information

<><>Edit>: 为了在法典中做到这一点,你还可以设定一个习俗目标:

using NLog; 
using NLog.Targets; 

namespace MyNamespace 
{ 
    [Target("MyFirst")] 
    public sealed class MyFirstTarget: TargetWithLayout 
    { 
        public MyFirstTarget()
        {
            this.Host = "localhost";
        }

        [Required] 
        public string Host { get; set; }

        protected override void Write(LogEventInfo logEvent) 
        { 
            string logMessage = this.Layout.Render(logEvent); 

            SendTheMessageToRemoteHost(this.Host, logMessage); 
        } 

        private void SendTheMessageToRemoteHost(string host, string message) 
        { 
            // Detect your database state here or do something else with the error.
        } 
    } 
}

并使用:

<nlog> 
  <extensions> 
    <add assembly="MyAssembly"/> 
  </extensions> 
  <targets> 
    <target name="a1" type="MyFirst" host="localhost"/> 
  </targets> 
  <rules> 
    <logger name="*" minLevel="Info" appendTo="a1"/> 
  </rules> 
</nlog>

See this page for more information.





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签