2016-09-14 42 views

回答

-1

配置文件

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <configSections> 
    <section name="Log" type="Zivsoft.Log.Handler,Zivsoft.Log"/> 
    </configSections> 
    <Log level="DEBUG"> 
    <LogFile>log.log</LogFile> 
    <Console len="3">true</Console> 
    <XmlLog enabled="true">log.xml</XmlLog> 
    <ShowHeader>false</ShowHeader> 
    </Log> 
</configuration> 

示例代碼

using System; 
using Zivsoft.Log; 

namespace LogTest 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      Logger.LogDebug("debug"); //log for debug 
      Logger.LogError("error"); //log for error 
      Logger.LogInfo("Info"); //log for information 
      Logger.LogWarning("Warning"); //log for warning 
      Console.Read(); //pause the console 
      try 
      { 
       int i=55/0; 
      } 
      catch(Exception ex) 
      { 
       Logger.LogDebug(ex.Message); //log for Exception 
      } 
     } 
    } 
} 
+0

有一個在ASP.NET沒有'靜態無效Main'方法。 – mason

+0

嗨abhishek信息日誌和錯誤日誌存儲在單個文件中。但我需要將信息日誌存儲在一個文件中,並使用logger.net將錯誤日誌存儲在另一個文件中 – narasimhulu

+0

Hello @narasimhulu,在調用記錄器之前的catch塊中更改記錄器文件路徑, Logger.DefaultBinaryFile.Directory =「C:\\ Logs」; //和/或 Logger.DefaultTextFile.Directory =「C:\\ Logs」; –