Skip to content

couldn't create a log file using AzureAppendBlobAppender  #78

@saiseisei

Description

@saiseisei

I use a web.config contain the log4net configuration.
but I check the blob container, and it has nothing yet.
I was searching the idea for a long time as a beginner.
and I don't know why.

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

// public void Configure(IApplicationBuilder app, IHostingEnvironment env) 
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 !");
}

As the ConsoleAppender is working well , the BlobAppender works nothing .
My Azure Storage Explorer has no file created.
Are there Any ideas for me .
@matt-lethargic
@dstj
@stemarie
@mryderie
@Thumann

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions