You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello all, I just tried to create a c# console program using the nuget package latest version and it is not working.
Console program
`
using System;
using log4net;
using log4net.Config;
using System.IO;
using System.Reflection;
using System.Net.Http;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using log4stash;
//the above is test code used to make sure I can send messages to elk. Had to modify the code produced by postman because of certificate errors.
try
{
// Ensure log4net is configured
var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
// Reflectively modify the HttpClientHandler of the ElasticSearchAppender
var log4stashAppender = (ElasticSearchAppender)LogManager.GetRepository().GetAppenders()[0];
var clientField = typeof(ElasticSearchAppender).GetField("_client", BindingFlags.NonPublic | BindingFlags.Instance);
if (clientField != null)
{
var httpClient = (HttpClient)clientField.GetValue(log4stashAppender);
var customHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors) => true
};
var customClient = new HttpClient(customHandler);
clientField.SetValue(log4stashAppender, customClient);
}
log4stashAppender.ActivateOptions();
// Log messages
logger.Debug("This is a DEBUG message.");
logger.Info("This is an INFO message.");
logger.Warn("This is a WARN message.");
logger.Error("This is an ERROR message.");
logger.Error("kaboom!", new ApplicationException("An error occurred"));
Console.WriteLine("Log messages have been sent to Elasticsearch....maybe....");
}
catch (Exception ex)
{
Console.WriteLine("Error occurred: " + ex.Message);
}
}
}
log4net: log4net assembly [log4net, Version=2.0.9.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a]. Loaded from [C:\CodeRepo\Dev\ELKTest\ELKTest\bin\Debug\net5.0\log4net.dll]. (.NET Runtime [5.0.17] on Microsoft Windows NT 10.0.19045.0) log4net: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy] log4net: Creating repository for assembly [ELKTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] log4net: Assembly [ELKTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] Loaded From [C:\CodeRepo\Dev\ELKTest\ELKTest\bin\Debug\net5.0\ELKTest.dll] log4net: Assembly [ELKTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified. log4net: Assembly [ELKTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy] log4net: Creating repository [log4net-default-repository] using type [log4net.Repository.Hierarchy.Hierarchy] log4net: configuring repository [log4net-default-repository] using file [C:\CodeRepo\Dev\ELKTest\ELKTest\bin\Debug\net5.0\log4net.config] watching for file updates log4net: configuring repository [log4net-default-repository] using file [C:\CodeRepo\Dev\ELKTest\ELKTest\bin\Debug\net5.0\log4net.config] log4net: configuring repository [log4net-default-repository] using stream log4net: loading XML configuration log4net: Configuring Repository [log4net-default-repository] log4net: Configuration update mode [Merge]. log4net: Logger [root] Level string is [ALL]. log4net: Logger [root] level set to [name="ALL",value=-2147483648]. log4net: Loading Appender [console] type: [log4net.Appender.ConsoleAppender] log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Setting Property [ConversionPattern] to String value [%date %level %logger - %message%newline] log4net: Converter [date] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [level] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [logger] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [literal] Option [ - ] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Setting Property [Layout] to object [log4net.Layout.PatternLayout] log4net: Created Appender [console] log4net: Adding appender named [console] to logger [root]. log4net: Loading Appender [ElasticSearchAppender] type: [log4stash.ElasticSearchAppender, log4stash] log4net: Setting Property [Server] to String value [server] log4net: Setting Property [Port] to Int32 value [9200] log4net: Setting Property [Ssl] to Boolean value [False] log4net: Setting Property [AllowSelfSignedServerCert] to Boolean value [True] log4net: Setting Property [IndexName] to String value [elk_test] log4net: Setting Property [IndexType] to String value [LogEvent] log4net: Setting Property [BulkSize] to Int32 value [1] log4net: Setting Property [BulkIdleTimeout] to Int32 value [10000] log4net: Setting Property [IndexAsync] to Boolean value [False] log4net: Setting Property [ElasticSearchTimeout] to Int32 value [10000] log4net:ERROR Object type not specified. Cannot create object of type [log4stash.Authentication.AuthenticationMethodChooser]. Missing Value or Type. log4net:ERROR Failed to create object to set param: AuthenticationMethod log4net: Setting Property [Key] to String value [Environment] log4net: Setting Property [Value] to String value [DEV] log4net: Setting Collection Property [AddAdd] to object [log4stash.Filters.AddValueFilter] log4net: Setting Property [Key] to String value [log4net:Identity] log4net: Setting Collection Property [AddRemove] to object [log4stash.Filters.RemoveKeyFilter] log4net: Setting Property [SourceKey] to String value [Message] log4net: Setting Property [ValueSplit] to String value [|] log4net: Setting Property [FieldSplit] to String value [ ,] log4net: Setting Collection Property [AddKv] to object [log4stash.Filters.KvFilter] log4net: Setting Property [ElasticFilters] to object [log4stash.ElasticAppenderFilters] log4net: Created Appender [ElasticSearchAppender] log4net: Adding appender named [ElasticSearchAppender] to logger [root]. log4net: Hierarchy Threshold [] log4net: configuring repository [log4net-default-repository] using .config file section log4net: Application config file is [C:\CodeRepo\Dev\ELKTest\ELKTest\bin\Debug\net5.0\ELKTest.dll.config] log4net: Configuring Repository [log4net-default-repository] log4net: Configuration update mode [Merge]. log4net: Logger [root] Level string is [ALL]. log4net: Logger [root] level set to [name="ALL",value=-2147483648]. log4net: Loading Appender [console] type: [log4net.Appender.ConsoleAppender] log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Setting Property [ConversionPattern] to String value [%date %level %logger - %message%newline] log4net: Converter [date] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [level] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [logger] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [literal] Option [ - ] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Setting Property [Layout] to object [log4net.Layout.PatternLayout] log4net: Created Appender [console] log4net: Adding appender named [console] to logger [root]. log4net: Loading Appender [ElasticSearchAppender] type: [log4stash.ElasticSearchAppender, log4stash] log4net: Setting Property [Server] to String value [server.com] log4net: Setting Property [Port] to Int32 value [9200] log4net: Setting Property [Ssl] to Boolean value [False] log4net: Setting Property [AllowSelfSignedServerCert] to Boolean value [True] log4net: Setting Property [IndexName] to String value [elk_test] log4net: Setting Property [IndexType] to String value [LogEvent] log4net: Setting Property [BulkSize] to Int32 value [1] log4net: Setting Property [BulkIdleTimeout] to Int32 value [10000] log4net: Setting Property [IndexAsync] to Boolean value [False] log4net: Setting Property [ElasticSearchTimeout] to Int32 value [10000] log4net:ERROR Object type not specified. Cannot create object of type [log4stash.Authentication.AuthenticationMethodChooser]. Missing Value or Type. log4net:ERROR Failed to create object to set param: AuthenticationMethod log4net: Setting Property [Key] to String value [Environment] log4net: Setting Property [Value] to String value [DEV] log4net: Setting Collection Property [AddAdd] to object [log4stash.Filters.AddValueFilter] log4net: Setting Property [Key] to String value [log4net:Identity] log4net: Setting Collection Property [AddRemove] to object [log4stash.Filters.RemoveKeyFilter] log4net: Setting Property [SourceKey] to String value [Message] log4net: Setting Property [ValueSplit] to String value [|] log4net: Setting Property [FieldSplit] to String value [ ,] log4net: Setting Collection Property [AddKv] to object [log4stash.Filters.KvFilter] log4net: Setting Property [ElasticFilters] to object [log4stash.ElasticAppenderFilters] log4net: Created Appender [ElasticSearchAppender] log4net: Adding appender named [ElasticSearchAppender] to logger [root]. log4net: Hierarchy Threshold [] Error occurred: Unable to cast object of type 'log4net.Appender.ConsoleAppender' to type 'log4stash.ElasticSearchAppender'. log4net: Shutdown called on Hierarchy [log4net-default-repository]
The text was updated successfully, but these errors were encountered:
Hello all, I just tried to create a c# console program using the nuget package latest version and it is not working.
Console program
`
using System;
using log4net;
using log4net.Config;
using System.IO;
using System.Reflection;
using System.Net.Http;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using log4stash;
[assembly: XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
namespace ELKTest
{
internal class Program
{
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
//the above is test code used to make sure I can send messages to elk. Had to modify the code produced by postman because of certificate errors.
try
{
// Ensure log4net is configured
var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
}
`
here is my App.config
`
`
here is the errors/output I am getting.
log4net: log4net assembly [log4net, Version=2.0.9.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a]. Loaded from [C:\CodeRepo\Dev\ELKTest\ELKTest\bin\Debug\net5.0\log4net.dll]. (.NET Runtime [5.0.17] on Microsoft Windows NT 10.0.19045.0) log4net: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy] log4net: Creating repository for assembly [ELKTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] log4net: Assembly [ELKTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] Loaded From [C:\CodeRepo\Dev\ELKTest\ELKTest\bin\Debug\net5.0\ELKTest.dll] log4net: Assembly [ELKTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified. log4net: Assembly [ELKTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy] log4net: Creating repository [log4net-default-repository] using type [log4net.Repository.Hierarchy.Hierarchy] log4net: configuring repository [log4net-default-repository] using file [C:\CodeRepo\Dev\ELKTest\ELKTest\bin\Debug\net5.0\log4net.config] watching for file updates log4net: configuring repository [log4net-default-repository] using file [C:\CodeRepo\Dev\ELKTest\ELKTest\bin\Debug\net5.0\log4net.config] log4net: configuring repository [log4net-default-repository] using stream log4net: loading XML configuration log4net: Configuring Repository [log4net-default-repository] log4net: Configuration update mode [Merge]. log4net: Logger [root] Level string is [ALL]. log4net: Logger [root] level set to [name="ALL",value=-2147483648]. log4net: Loading Appender [console] type: [log4net.Appender.ConsoleAppender] log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Setting Property [ConversionPattern] to String value [%date %level %logger - %message%newline] log4net: Converter [date] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [level] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [logger] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [literal] Option [ - ] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Setting Property [Layout] to object [log4net.Layout.PatternLayout] log4net: Created Appender [console] log4net: Adding appender named [console] to logger [root]. log4net: Loading Appender [ElasticSearchAppender] type: [log4stash.ElasticSearchAppender, log4stash] log4net: Setting Property [Server] to String value [server] log4net: Setting Property [Port] to Int32 value [9200] log4net: Setting Property [Ssl] to Boolean value [False] log4net: Setting Property [AllowSelfSignedServerCert] to Boolean value [True] log4net: Setting Property [IndexName] to String value [elk_test] log4net: Setting Property [IndexType] to String value [LogEvent] log4net: Setting Property [BulkSize] to Int32 value [1] log4net: Setting Property [BulkIdleTimeout] to Int32 value [10000] log4net: Setting Property [IndexAsync] to Boolean value [False] log4net: Setting Property [ElasticSearchTimeout] to Int32 value [10000] log4net:ERROR Object type not specified. Cannot create object of type [log4stash.Authentication.AuthenticationMethodChooser]. Missing Value or Type. log4net:ERROR Failed to create object to set param: AuthenticationMethod log4net: Setting Property [Key] to String value [Environment] log4net: Setting Property [Value] to String value [DEV] log4net: Setting Collection Property [AddAdd] to object [log4stash.Filters.AddValueFilter] log4net: Setting Property [Key] to String value [log4net:Identity] log4net: Setting Collection Property [AddRemove] to object [log4stash.Filters.RemoveKeyFilter] log4net: Setting Property [SourceKey] to String value [Message] log4net: Setting Property [ValueSplit] to String value [|] log4net: Setting Property [FieldSplit] to String value [ ,] log4net: Setting Collection Property [AddKv] to object [log4stash.Filters.KvFilter] log4net: Setting Property [ElasticFilters] to object [log4stash.ElasticAppenderFilters] log4net: Created Appender [ElasticSearchAppender] log4net: Adding appender named [ElasticSearchAppender] to logger [root]. log4net: Hierarchy Threshold [] log4net: configuring repository [log4net-default-repository] using .config file section log4net: Application config file is [C:\CodeRepo\Dev\ELKTest\ELKTest\bin\Debug\net5.0\ELKTest.dll.config] log4net: Configuring Repository [log4net-default-repository] log4net: Configuration update mode [Merge]. log4net: Logger [root] Level string is [ALL]. log4net: Logger [root] level set to [name="ALL",value=-2147483648]. log4net: Loading Appender [console] type: [log4net.Appender.ConsoleAppender] log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Setting Property [ConversionPattern] to String value [%date %level %logger - %message%newline] log4net: Converter [date] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [level] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [logger] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [literal] Option [ - ] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Setting Property [Layout] to object [log4net.Layout.PatternLayout] log4net: Created Appender [console] log4net: Adding appender named [console] to logger [root]. log4net: Loading Appender [ElasticSearchAppender] type: [log4stash.ElasticSearchAppender, log4stash] log4net: Setting Property [Server] to String value [server.com] log4net: Setting Property [Port] to Int32 value [9200] log4net: Setting Property [Ssl] to Boolean value [False] log4net: Setting Property [AllowSelfSignedServerCert] to Boolean value [True] log4net: Setting Property [IndexName] to String value [elk_test] log4net: Setting Property [IndexType] to String value [LogEvent] log4net: Setting Property [BulkSize] to Int32 value [1] log4net: Setting Property [BulkIdleTimeout] to Int32 value [10000] log4net: Setting Property [IndexAsync] to Boolean value [False] log4net: Setting Property [ElasticSearchTimeout] to Int32 value [10000] log4net:ERROR Object type not specified. Cannot create object of type [log4stash.Authentication.AuthenticationMethodChooser]. Missing Value or Type. log4net:ERROR Failed to create object to set param: AuthenticationMethod log4net: Setting Property [Key] to String value [Environment] log4net: Setting Property [Value] to String value [DEV] log4net: Setting Collection Property [AddAdd] to object [log4stash.Filters.AddValueFilter] log4net: Setting Property [Key] to String value [log4net:Identity] log4net: Setting Collection Property [AddRemove] to object [log4stash.Filters.RemoveKeyFilter] log4net: Setting Property [SourceKey] to String value [Message] log4net: Setting Property [ValueSplit] to String value [|] log4net: Setting Property [FieldSplit] to String value [ ,] log4net: Setting Collection Property [AddKv] to object [log4stash.Filters.KvFilter] log4net: Setting Property [ElasticFilters] to object [log4stash.ElasticAppenderFilters] log4net: Created Appender [ElasticSearchAppender] log4net: Adding appender named [ElasticSearchAppender] to logger [root]. log4net: Hierarchy Threshold [] Error occurred: Unable to cast object of type 'log4net.Appender.ConsoleAppender' to type 'log4stash.ElasticSearchAppender'. log4net: Shutdown called on Hierarchy [log4net-default-repository]
The text was updated successfully, but these errors were encountered: