невозможно создать файл журнала с помощью log4net.Appender.AzureAppendBlobAppender - PullRequest
0 голосов
/ 28 июня 2018

Я использую web.config с конфигурацией log4net. но я проверяю контейнер BLOB-объектов, и у него еще ничего нет. Поскольку никаких исключений или ошибок не было напечатано, я долго искал эту идею как новичок. Тем не менее, я не знаю почему.

----- web.config -----

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>

  <appSettings>
    <add key="log4net.Config" value="log4net.Config" />
    <add key="log4net.Config.watch" value="true" />
    <add key="log4net.Internal.Debug" value="true" />
  </appSettings>

  <system.diagnostics>
    <trace autoflush="true">
      <listeners>
        <add
            name="TextWriterTraceListener"
            type="System.Diagnostics.TextWriterTraceListener"
            initializeData="D:\srcCSharp\SampleApp\WebApplicationTest\logs\log4net.txt" />
      </listeners>
    </trace>
  </system.diagnostics>

  <log4net>


    <!-- Azure AppendBlob Appender, uncomment, set proper BucketName and AWS credentials (appSettings) to try it out -->
    <appender name="BlobAppender" type="log4net.Appender.AzureAppendBlobAppender, log4net.Appender.Azure">
      <!-- You can either specify a connection string or use the ConnectionStringName property instead -->
      <param name="ConnectionString" value="UseDevelopmentStorage=true" />
      <param name="ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=logstorage;AccountKey=3r90Axf+UO;EndpointSuffix=core.windows.net" />
      <param name="ContainerName" value="logs" />
      <param name="DirectoryName" value="%date{yyyyMM}" />
      <!--<param name="ConnectionStringName" value="GlobalConfigurationString" />-->
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="Log At %date{yyyy/MM/dd HH:mm:ss, fff} [%thread] %-5level %logger  - %message%newline" />
      </layout>
    </appender>

    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="Log At %date{yyyy/MM/dd HH:mm:ss,fff} [%thread][%-5level]%logger  - %message%newline" />
      </layout>
    </appender>

    <root>
      <level value="ALL" />
      <appender-ref ref="BlobAppender" />
      <appender-ref ref="ConsoleAppender" />
    </root>
  </log4net>

  <connectionStrings>
    <!-- Provided as an example for specifying a global connection string for multiple appenders -->
    <add name="GlobalConfigurationString" connectionString="UseDevelopmentStorage=true" />
  </connectionStrings>

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.6.0.0" newVersion="5.6.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.6.0.0" newVersion="5.6.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.6.0.0" newVersion="5.6.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

</configuration>

----- Startup.cs -----

XmlDocument XmlDoc = new XmlDocument();
string configFile = "web.config";
XmlDoc.Load(File.OpenRead(configFile));
var repo = log4net.LogManager.CreateRepository(Assembly.GetEntryAssembly(),typeof(log4net.Repository.Hierarchy.Hierarchy));
XmlNodeList elemList = XmlDoc.GetElementsByTagName("log4net");
log4net.Config.XmlConfigurator.Configure(repo, (XmlElement)elemList[0]);

ILog Logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
if(Logger.IsDebugEnabled)
{
    Logger.Debug(" ---- All is well !");
}

ConsoleAppender также работает. BlobAppender не работает. так как в My Azure Storage Explorer нет файлов, исключений и ошибок нет. Я пытаюсь долго. Помоги мне.

...