简体   繁体   中英

Log from multiple projects in single solution

I've got a solution where I need to log from different assemblies using log4net. The first project in the solution ( PCBClient.cs , a web client) logs as expected, but the next one ( WriteUtilities.cs , backend database functions) doesn't log at all. I've followed the instructions on Falafel.com , as well as the follow-on instructions on this SO page , as well as the thread on DreamInCode.net .

Obviously I'm missing something.

I've added the initial project PCBClient as a reference in WriteUtilities. I can't do the reciprocal as it would create a circular reference, maybe I need to make the references go the other way? I've created a new logger in the web.config of PCBClient appending the name of the referenced assembly per the log4net FAQ: Can I load an appender from another assembly? using the specified form:

<appender name="..." type="MyNamespace.MyAppender, MyAssembly">

(I'm reasonably sure I don't need the .cs after the name of the assembly?):

  <appender name="WriteUtility_TransactionLog" type="log4net.Appender.FileAppender, WriteUtilities">
  <File value="WriteUtilityTransactions.log"/>
  <AppendToFile value="true"/>
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date{yyyy-MM-ddTHH:mm:ss} %logger - %message%newline"/>
  </layout>
</appender>

Created a reference to it in the web.config as well:

<logger name="WriteUtility_TransactionLog">
  <level value="ALL"/>
  <appender-ref ref="WriteUtility_TransactionLog"/>
</logger>

Then marked the properties of both the web.config in PCBClient and the linked web.config in WriteUtilities as "Copy if newer".

In the assembly WriteUtilities.cs I've added:

    private static readonly ILog WriteUtilities_TransactionLog = LogManager.GetLogger("WriteUtility_TransactionLog");

In AssemblyInfo.cs in the PCBClient project I've added:

// Log4Net configuration
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4Net.config", Watch = true)]

And commented out the original logging references in both PCBClient & WriteUtilities so they should both point to the one above (I think):

//point at logging .dll
//[assembly: log4net.Config.XmlConfigurator(Watch = true)]

I still can't log from the WriteUtilties, what am I missing?

Change your tag so that it looks like:

<log4net debug="true">

Perhaps that would be of help to you to solve the mystery.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM