问题
We have a search module on DNN and would like to create a log file which will send search terms which did not bring back any matches.
The log will will then have to be emailed to the admin (Perhaps the DNN schedule manager can be used?).
I see that DNN has Log4Net, but won't it be better to write a txt file and write to it?
Does anyone have suggestions on how the Paths to save the file would work and if there are any existing DNN functionality I can use?
回答1:
You can also use your DotNetNuke.log4net.config
Example writing to multiple files:
<log4net>
<appender name="File1Appender" type="log4net.Appender.FileAppender">
<file value="log-file-1.txt" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %message%newline" />
</layout>
</appender>
<appender name="File2Appender" type="log4net.Appender.FileAppender">
<file value="log-file-2.txt" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="File1Appender" />
<appender-ref ref="File2Appender" />
</root>
回答2:
It is always best to use the build-in features as much as possible before you create your own. DNN has a log system you can use with just 2 lines of code.
using DotNetNuke.Services.Log.EventLog;
EventLogController logController = new EventLogController();
logController.AddLog("Log Entry", "The detailed message goes here.", PortalSettings, UserId, EventLogController.EventLogType.ADMIN_ALERT);
If you really want to create your own log, do not use a file but a database table.
来源:https://stackoverflow.com/questions/50130674/create-a-log-file-for-a-custom-dnn-module