Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nlog-Mongodb创建集合_Mongodb_Asp.net Core_Nlog - Fatal编程技术网

Nlog-Mongodb创建集合

Nlog-Mongodb创建集合,mongodb,asp.net-core,nlog,Mongodb,Asp.net Core,Nlog,我使用的是Nlog(4.7.5)、Nlog.mongo(4.6.0.118)和mongoDB.Driver(2.11.3)。 使用mongodb登录时,我需要创建这样的集合“log-2020-10-18”。 因此,第18个日期日志存储在此集合中。第二天或以后,日志将存储在日志-${shortdate}集合中。日志每天以集合名称的格式存储。 简而言之,我想在mongodb中按天存储日志,这样就可以很容易地查看日常日志。 我可以在运行时创建集合吗(我是指在nlog.config文件中) 那么这有可能

我使用的是Nlog(4.7.5)、Nlog.mongo(4.6.0.118)和mongoDB.Driver(2.11.3)。 使用mongodb登录时,我需要创建这样的集合
“log-2020-10-18”
。 因此,第18个日期日志存储在此集合中。第二天或以后,日志将存储在
日志-${shortdate}
集合中。日志每天以集合名称的格式存储。 简而言之,我想在mongodb中按天存储日志,这样就可以很容易地查看日常日志。 我可以在运行时创建集合吗(我是指在nlog.config文件中) 那么这有可能做到吗?怎么做

这是mongodb的目标

    <target xsi:type="Database"
                    name="mongo"
                    includeDefaults="false"
                    connectionString="mongodb://localhost/financeLogs"
                    collectionName="log-${shortdate}"
                    databaseName="financeLogs">
                <property name="LongDate" layout="${longdate}" bsonType="DateTime" />
                <property name="Level" layout="${level}"/>
                <property name="Message" layout="${message}"/>
    
            </target>
您是否尝试过此方法(注意使用了
xsi:type=“Mongo”
):



请确保使用(或更新版本)以改进对在
collectionName=

@BhavinVarsur中使用
${shortdate}
的支持。BhavinVarsur“不工作”是非常模糊的。是否创建了第一个集合?是否无法在日滚动时创建下一个集合?能否启用NLog InternalLogger并在初始创建和日滚动时显示输出?另见:啊。我现在看到了问题:(
\u defaultLogEvent
对于滚动日期来说不是一个很好的值)我刚刚从[和你的答案中的集合名称中添加了目标。我很惊讶它现在可以工作了。谢谢!!@BhavinVarsur创建了pull请求来改进对日期时间布局渲染器的支持:@BhavinVarsur现在已经发布,支持${shortdate}在collection-name.中,还记得使用
xsi:type=“Mongo”
而不是
xsi:type=“Database”
2020-10-18 14:26:06.1806 Warn Error when setting 'log-${shortdate}' on attibute 'collectionName' Exception: System.NotSupportedException: Parameter collectionName not supported on DatabaseTarget
   at NLog.Internal.PropertyHelper.SetPropertyFromString(Object obj, String propertyName, String value, ConfigurationItemFactory configurationItemFactory)
   at NLog.Config.LoggingConfigurationParser.ConfigureObjectFromAttributes(Object targetObject, ILoggingConfigurationElement element, Boolean ignoreType)
2020-10-18 14:26:06.2640 Error Exception when parsing D:\Git\finance.api\FinanceAPI\bin\Debug\netcoreapp3.1\nlog.Development.config.  Exception: System.NotSupportedException: Parameter collectionName not supported on DatabaseTarget
   at NLog.Internal.PropertyHelper.SetPropertyFromString(Object obj, String propertyName, String value, ConfigurationItemFactory configurationItemFactory)
   at NLog.Config.LoggingConfigurationParser.ConfigureObjectFromAttributes(Object targetObject, ILoggingConfigurationElement element, Boolean ignoreType)
   at NLog.Config.LoggingConfigurationParser.ParseTargetElement(Target target, ILoggingConfigurationElement targetElement, Dictionary`2 typeNameToDefaultTargetParameters)
   at NLog.Config.LoggingConfigurationParser.ParseTargetsElement(ILoggingConfigurationElement targetsElement)
   at NLog.Config.LoggingConfigurationParser.ParseNLogSection(ILoggingConfigurationElement configSection)
   at NLog.Config.XmlLoggingConfiguration.ParseNLogSection(ILoggingConfigurationElement configSection)
   at NLog.Config.LoggingConfigurationParser.LoadConfig(ILoggingConfigurationElement nlogConfig, String basePath)
   at NLog.Config.XmlLoggingConfiguration.ParseNLogElement(ILoggingConfigurationElement nlogElement, String filePath, Boolean autoReloadDefault)
   at NLog.Config.XmlLoggingConfiguration.ParseTopLevel(NLogXmlElement content, String filePath, Boolean autoReloadDefault)
   at NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors)
2020-10-18 14:26:06.2980 Warn Error has been raised. Exception: NLog.NLogConfigurationException: Exception when parsing D:\Git\finance.api\FinanceAPI\bin\Debug\netcoreapp3.1\nlog.Development.config. 
 ---> System.NotSupportedException: Parameter collectionName not supported on DatabaseTarget
   at NLog.Internal.PropertyHelper.SetPropertyFromString(Object obj, String propertyName, String value, ConfigurationItemFactory configurationItemFactory)
   at NLog.Config.LoggingConfigurationParser.ConfigureObjectFromAttributes(Object targetObject, ILoggingConfigurationElement element, Boolean ignoreType)
   at NLog.Config.LoggingConfigurationParser.ParseTargetElement(Target target, ILoggingConfigurationElement targetElement, Dictionary`2 typeNameToDefaultTargetParameters)
   at NLog.Config.LoggingConfigurationParser.ParseTargetsElement(ILoggingConfigurationElement targetsElement)
   at NLog.Config.LoggingConfigurationParser.ParseNLogSection(ILoggingConfigurationElement configSection)
   at NLog.Config.XmlLoggingConfiguration.ParseNLogSection(ILoggingConfigurationElement configSection)
   at NLog.Config.LoggingConfigurationParser.LoadConfig(ILoggingConfigurationElement nlogConfig, String basePath)
   at NLog.Config.XmlLoggingConfiguration.ParseNLogElement(ILoggingConfigurationElement nlogElement, String filePath, Boolean autoReloadDefault)
   at NLog.Config.XmlLoggingConfiguration.ParseTopLevel(NLogXmlElement content, String filePath, Boolean autoReloadDefault)
   at NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors)
   --- End of inner exception stack trace ---
2020-10-18 14:26:06.3558 Info Validating config: TargetNames=file, fileAsException, ConfigItems=56, FilePath=D:\Git\finance.api\FinanceAPI\bin\Debug\netcoreapp3.1\nlog.Development.config
2020-10-18 14:26:06.3859 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: file
2020-10-18 14:26:06.3975 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: fileAsException