Click here to Skip to main content
16,021,687 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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
XML
<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

C#
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
XML
<pre lang="cs">if (excelQuoteCollection == null || excelQuoteCollection.Count() == 0)
            {
                NLogger.Error(&quot;EXCEL quote collection is null.&quot;);
                return;
            }</pre>


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
Posted
Comments
shivani 2013 24-Mar-14 6:30am    
Is there no one who can help me on this?

1 solution

I resolved myself..........use in app.config
HTML
<targets>
        <target name="file" xsi:type="File" layout="${longdate} ${logger} ${message}" filename="${basedir}/${level}.log" xmlns:xsi="#unknown" />
    </targets>
<rules>
       <logger name="*" minlevel="Debug" writeto="file" />
    </rules>


hope it will help others

use link
https://github.com/nlog/NLog/wiki/File-target
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900