创建日志文件以获取错误和信息 [英] Creating log file for error and information

查看:140
本文介绍了创建日志文件以获取错误和信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用mvc创建了一个应用程序。我想创建2个日志文件..一个用于出错,第二个用于获取信息。

低于我在app.config中的代码

I have created one application using mvc.I want to create 2 log files ..one for error and second for information.
below my code in app.config

<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <targets>
      <target name="logfile" xsi:type="File" fileName="${basedir}/${date:format=yyyy-MM-dd}-webapi-error.log" />
      <target name="infofile" xsi:type="File" fileName="${basedir}/${date:format=yyyy-MM-dd}-webapi-info.log" />
      <target name="eventlog" xsi:type="EventLog" layout="${message}" log="GACensus" source="GA Census Web Api" />
    </targets>
    <rules>
      <!--<Trace, Debug, Info, Warn, Error, Fatal>-->
      <logger name="*" minlevel="Warn" writeTo="logfile" />
      <logger name="*" minlevel="Error" writeTo="eventlog" />
      <logger name="*" minlevel="Info" writeTo="infofile" />
    </rules>
  </nlog>





以下信息源代码





and below source code for Information

if (response.IsSuccessStatusCode)
              quoteCollection = JsonConvert.DeserializeObject<IEnumerable<Domain.ApiDto.QuoteXML.Quote>>(response.Content.ReadAsStringAsync().Result);
          else
              NLogger.Info(string.Format("GetQuoteForXml(XML Collection): {0}/{1}; Response Status : {2}({3})",
                          CommonConstants.UserAPIServiceURI, CommonConstants.GetOrionBrokerId, (int)response.StatusCode, response.ReasonPhrase));



另一个错误代码


another code for error

<pre lang="cs">if (excelQuoteCollection == null || excelQuoteCollection.Count() == 0)
            {
                NLogger.Error(&quot;EXCEL quote collection is null.&quot;);
                return;
            }</pre>





现在发生的事情是它给我两个日志文件的错误消息来了

pls帮助为什么在信息日志文件中出现错误消息。



帮助将是可感知的



now what happens it is giving me two log files in both error message coming
pls help why in info log file error message coming.

help will be appreciable

推荐答案

{basedir} /
{basedir}/


{date:format = yyyy-MM-dd} -webapi-error.log / >
< < span class =code-leadattribute> target name = infofile xsi :type = 文件 fileName =
{date:format=yyyy-MM-dd}-webapi-error.log" /> <target name="infofile" xsi:type="File" fileName="


{basedir} /
{basedir}/


这篇关于创建日志文件以获取错误和信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆