AssemblyInfo.vb
<Assembly: log4net.Config.XmlConfigurator(Watch:=True)>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Public Class Logger
'Private Shared ReadOnly log As log4net.ILog = vbNull
Public Sub New()
End Sub
Public Shared Sub writeLog(ByVal logInfoMsg As String)
Dim appConfigFilePath As String = AppDomain.CurrentDomain.BaseDirectory
log4net.Config.XmlConfigurator.Configure(New System.IO.FileInfo("C:\Users\han\Desktop\参照\MVCTEST\ClassLibrary1\app.config"))
Dim log As log4net.ILog = log4net.LogManager.
GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
log.Info(logInfoMsg)
log.Error(logInfoMsg)
log.Warn(logInfoMsg)
End Sub
End Class
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
既存コード略...
</system.diagnostics>
<configSections> <section name="log4net" type=" log4net.Config.Log4NetConfigurationSectionHandler,log4net" /> </configSections> <log4net> <!-- ログ出力先の定義 --> <appender name="LogFileAppender" type="log4net.Appender.FileAppender" > <!-- 作成するログファイル --> <param name="File" value="C:\log\log-file.txt" /> <!-- 追加 --> <param name="AppendToFile" value="true" /> <!-- ログの書式 --> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" /> </layout> </appender> <root> <!-- ログのレベルを指定 --> <!-- すべてのログレベルを出力 --> <level value="ALL" /> <!-- どのログ出力先を使用するか --> <appender-ref ref="LogFileAppender" /> </root> </log4net> </configuration>