1 year ago
#232909
LP1308
Add multiple log4net appenders
I'm currently trying to add a Microsoft Teaqms appender to my log4net file. In this file I already have different appenders. My current try looks like this:
<log4net debug="true">
<root>
<level value="WARN" />
<appender-ref ref="AdoNetAppender" />
<appender-ref ref="myMicrosoftTeamsAppender" />
</root>
<logger name="ErpLogger" additivity="false">
<level value="INFO"/>
<appender-ref ref="AdoNetAppender"/>
</logger>
<logger name="ChangeHistoryLogger" additivity="false">
<level value="INFO"/>
<appender-ref ref="AdoNetAppender"/>
</logger>
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<ReconnectOnError value="true" />
<connectionType
value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionStringName value="LogConnection" />
<commandText
value="INSERT INTO log4netlog ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
</appender>
<appender name="ConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
<threshold value="ALL" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5p %c %m%n" />
</layout>
</appender>
<appender name="myMicrosoftTeamsAppender" type="log4net.MicrosoftTeams.MicrosoftTeamsAppender, log4net.MicrosoftTeams">
<WebhookUrl value="my Teams URL" />
<titleLayout>
<conversionPattern value="Title - %p: %date [%c]" />
</titleLayout>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5level %logger - %message" />
</layout>
</appender>
</log4net>
So I already had an test project with this Teams appender and everytime I added a Log a message in the Teams channel gets created. But now I'm trying to add this in my real project and it doesn't work. I tried it with this code in my Startup class:
log4net.Config.XmlConfigurator.Configure();
var logger = LogManager.GetLogger("myMicrosoftTeamsAppender");
logger.Info("Info.");
logger.Fatal("Fatal!", new ArgumentException("42"));
How can I solve this? let me know if you need any other parts of the code :)
Edit: I found this in the Output:
...
log4net: Loading Appender [teams] type: [log4net.MicrosoftTeams.MicrosoftTeamsAppender, log4net.MicrosoftTeams]
log4net:ERROR Could not create Appender [teams] of type [log4net.MicrosoftTeams.MicrosoftTeamsAppender, log4net.MicrosoftTeams]. Reported error follows.
System.IO.FileNotFoundException: Die Datei oder Assembly "log4net.MicrosoftTeams" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden.
Dateiname: "log4net.MicrosoftTeams"
bei System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
bei System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
bei System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
bei System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
bei log4net.Util.SystemInfo.GetTypeFromString(Assembly relativeAssembly, String typeName, Boolean throwOnError, Boolean ignoreCase)
bei log4net.Util.SystemInfo.GetTypeFromString(String typeName, Boolean throwOnError, Boolean ignoreCase)
bei log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
...
Update: I'm just getting this error now:
log4net:ERROR Appender named [myMicrosoftTeamsAppender] not found.
c#
.net
logging
log4net
appender
0 Answers
Your Answer