だから、私はNLogを試していますが、落ち続けます。私がこれまでに得たものを通してみましょう。NLogの設定が正しくありませんか?
マイNLog.configファイル:私はこのようにそれをやっている何かを記録したいとき
private static Logger logger = LogManager.GetCurrentClassLogger();
そして:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="file" xsi:type="File"
layout="${longdate} ${logger} ${message}"
fileName="${basedir}/Logs/${shortdate}.log" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
</rules>
</nlog>
は、その後、私はこのように私のオブジェクトを作成しています:
:try
{
// Do something
}
catch (Exception ex)
{
logger.Fatal("ERROR {0}", ex);
return null;
}
しかし、私は次のエラーを取得しています
System.TypeInitializationException was unhandled
Message="The type initializer for 'Rhs.CMSSites.Services.GetBlogFeeds' threw an exception."
Source="GetBlogFeeds"
TypeName="Rhs.CMSSites.Services.GetBlogFeeds"
StackTrace:
at Rhs.CMSSites.Services.GetBlogFeeds.Main(String[] args)
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.NullReferenceException
Message="Object reference not set to an instance of an object."
Source="GetBlogFeeds"
StackTrace:
at Rhs.CMSSites.Services.GetBlogFeeds.UserDetails(String UserName) in C:\Dev\Rhs.CMSSites.Services\GetBlogFeeds\GetBlogFeeds\Program.cs:line 217
at Rhs.CMSSites.Services.GetBlogFeeds..cctor() in C:\Dev\Rhs.CMSSites.Services\GetBlogFeeds\GetBlogFeeds\Program.cs:line 25
InnerException:
アイデア?
編集
はおそらくこの先に言及している必要がありますが、これは、コマンドラインアプリです。 GetBlogFeedsはクラスの名前です。
EDIT2
[OK]を、私は絶対馬鹿してきました。私はUserDetails()
メソッド(NLogメソッドの使用を試みる)をと呼び、の前にロガークラスをインスタンス化していました。私はあなたに両方をupvoteするつもりです。ありがとう、申し訳ありません。
私はこの作業をしようとしている間にヌルを一時的に返します。 –
例外を除いて、戻り値はすべて問題です。メソッドを無効に変更して、まだクラッシュしていないかどうかを確認してください。 AskashMのように他にも問題があると言いました。あなたがnullを返す以外に、それは後でそれをチェックしないで、実際にnull値(あなたがいる)をそのnull例外に基づいて使用しないようにするならば、悪い習慣です。 –