Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

couldn't create a log file using AzureAppendBlobAppender #78

Open
saiseisei opened this issue Jun 28, 2018 · 1 comment
Open

couldn't create a log file using AzureAppendBlobAppender #78

saiseisei opened this issue Jun 28, 2018 · 1 comment

Comments

@saiseisei
Copy link

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

@jrex-hw
Copy link

jrex-hw commented Mar 30, 2021

When I try to use the AzureAppendBlobAppender i get the following error
log4net:ERROR Could not create Appender [AzureAppendBlobAppender] of type [log4net.Appender.AzureAppendBlobAppender, log4net.Appender.Azure]. Reported error follows.
System.MissingMethodException: Method not found: 'Boolean Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.CreateIfNotExists(Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions, Microsoft.WindowsAzure.Storage.OperationContext)'.
at log4net.Appender.AzureAppendBlobAppender.ActivateOptions()
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR Appender named [AzureAppendBlobAppender] not found.

The latest repos is using outdated and deprecated versions of nuget packages that have been and replaced..

NOTE: As of version 9.4.0, this library has been split into multiple parts and replaced: See https://www.nuget.org/packages/Microsoft.Azure.Storage.Blob/, https://www.nuget.org/packages/Microsoft.Azure.Storage.File/, https://www.nuget.org/packages/Microsoft.Azure.Storage.Queue/, and https://www.nuget.org/packages/Microsoft.Azure.Storage.Common/.
For table support, see https://www.nuget.org/packages/Microsoft.Azure.CosmosDB.Table/.
This client library enables working with the Microsoft Azure storage services which include the blob and file service for storing binary and text data, the table service for storing structured non-relational data, and the queue service for storing messages that may be accessed by a client.
For this release see notes - https://github.com/Azure/azure-storage-net/blob/master/README.md and https://github.com/Azure/azure-storage-net/blob/master/changelog.txt
Microsoft Azure Storage team's blog - http://blogs.msdn.com/b/windowsazurestorage/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants